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.

71 lines
1.7 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. require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
  16. class CacherTest extends PHPUnit_Framework_TestCase
  17. {
  18. private $mock;
  19. protected function setUp()
  20. {
  21. set_new_overload(array($this, 'newCallback'));
  22. }
  23. /**
  24. * @expectedException InitializationException
  25. * @expectedExcepptionMessage Cache driver
  26. */
  27. public function testNotExtendsCache()
  28. {
  29. Cacher::get('Cacher');
  30. }
  31. public function testGet()
  32. {
  33. $this->mock = $this->getMockForAbstractClass(
  34. 'Cache', /* name of class to mock */
  35. array(), /* list of methods to mock */
  36. 'CacheMock' /* name for mocked class */
  37. );
  38. $this->assertTrue(Cacher::get('Cache') instanceof Cache);
  39. }
  40. public function testCacheAlreadySet()
  41. {
  42. $this->assertTrue(Cacher::get('Cache') instanceof Cache);
  43. }
  44. protected function newCallback($className)
  45. {
  46. switch ($className) {
  47. case 'Cache':
  48. return 'CacheMock';
  49. default:
  50. return $className;
  51. }
  52. }
  53. public function tearDown()
  54. {
  55. unset_new_overload();
  56. }
  57. }