You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-25
  8. *
  9. * Unit tests for Cacher class
  10. */
  11. require_once dirname(__FILE__) . '/../../cache/Cache.php';
  12. require_once dirname(__FILE__) . '/../../cache/Cacher.php';
  13. require_once dirname(__FILE__) . '/../../Registry.php';
  14. require_once dirname(__FILE__) . '/../../Config.php';
  15. class CacherTest extends PHPUnit_Framework_TestCase
  16. {
  17. private $mock;
  18. protected function setUp()
  19. {
  20. set_new_overload(array($this, 'newCallback'));
  21. }
  22. /**
  23. * @expectedException Exception
  24. * @expectedExcepptionMessage Cache driver
  25. */
  26. public function testNotExtendsCache()
  27. {
  28. Cacher::get('Cacher');
  29. }
  30. public function testGet()
  31. {
  32. $this->mock = $this->getMockForAbstractClass(
  33. 'Cache', /* name of class to mock */
  34. array(), /* list of methods to mock */
  35. 'CacheMock' /* name for mocked class */
  36. );
  37. $this->assertTrue(Cacher::get('Cache') instanceof Cache);
  38. }
  39. public function testCacheAlreadySet()
  40. {
  41. $this->assertTrue(Cacher::get('Cache') instanceof Cache);
  42. }
  43. protected function newCallback($className)
  44. {
  45. switch ($className) {
  46. case 'Cache':
  47. return 'CacheMock';
  48. default:
  49. return $className;
  50. }
  51. }
  52. public function tearDown()
  53. {
  54. unset_new_overload();
  55. }
  56. }