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.

68 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. public function testNotExtendsCache()
  24. {
  25. $this->setExpectedException('InitializationException', 'Cache driver');
  26. Cacher::get('Cacher');
  27. }
  28. public function testGet()
  29. {
  30. $this->mock = $this->getMockForAbstractClass(
  31. 'Cache', /* name of class to mock */
  32. array(), /* list of methods to mock */
  33. 'CacheMock' /* name for mocked class */
  34. );
  35. $this->assertTrue(Cacher::get('Cache') instanceof Cache);
  36. }
  37. public function testCacheAlreadySet()
  38. {
  39. $this->assertTrue(Cacher::get('Cache') instanceof Cache);
  40. }
  41. protected function newCallback($className)
  42. {
  43. switch ($className) {
  44. case 'Cache':
  45. return 'CacheMock';
  46. default:
  47. return $className;
  48. }
  49. }
  50. public function tearDown()
  51. {
  52. unset_new_overload();
  53. }
  54. }