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.

126 lines
3.3 KiB

13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
13 years ago
  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-10-..
  8. *
  9. * Unit tests for Load class
  10. */
  11. require dirname(__FILE__) . '/../Load.php';
  12. class LoadTest extends PHPUnit_Framework_TestCase
  13. {
  14. private static $inc_dirs = array();
  15. private static $file;
  16. /**
  17. * @TODO: Load->buildAutoload() should recieve AutoloadBuilder as a parameter
  18. * @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
  19. * @expectedException UnexpectedValueException
  20. * @expectedException PHPUnit_Framework_Error
  21. */
  22. public static function setUpBeforeClass()
  23. {
  24. if (!defined('PATH')) {
  25. define('PATH', realpath(dirname(__FILE__) . '/../../..'));
  26. }
  27. // default application name
  28. if (!defined('APP')) {
  29. define('APP', 'lib/core/tests/face');
  30. }
  31. self::$file = PATH . '/' . APP . '/cache/autoload.php';
  32. // value - if dir exists (to delete it if it was created), default true
  33. self::$inc_dirs[PATH . '/' . APP . '/src'] = true;
  34. self::$inc_dirs[PATH . '/' . APP . '/cache'] = true;
  35. self::$inc_dirs[PATH . '/lib'] = true;
  36. foreach (self::$inc_dirs as $dir => &$is_exist) {
  37. if (!file_exists($dir)) {
  38. $is_exist = false;
  39. mkdir($dir, 0777, true);
  40. }
  41. }
  42. }
  43. public function testSetAutoLoadFrom()
  44. {
  45. // autoload
  46. Load::setAutoloadFrom(self::$file);
  47. $autoload = require(self::$file);
  48. $this->assertNotEmpty($autoload);
  49. Load::autoload('Action');
  50. }
  51. public function testDebugAutoload()
  52. {
  53. Load::setAutoloadFrom(self::$file);
  54. $autoload = require(self::$file);
  55. $this->assertNotEmpty($autoload);
  56. define('DEBUG', true);
  57. Load::autoload('Func');
  58. Load::autoload('Captcha');
  59. }
  60. public function testAutoloadArrayExists()
  61. {
  62. $this->assertFileExists(self::$file);
  63. }
  64. /**
  65. * @TODO: Load - check if input file returns array
  66. */
  67. public function testFileForArray()
  68. {
  69. $autoload = require(self::$file);
  70. $this->assertInternalType('array', $autoload);
  71. }
  72. public function testAutoloadArrayNotEmpty()
  73. {
  74. $autoload = require(self::$file);
  75. $this->assertNotEmpty($autoload);
  76. $this->assertArrayHasKey('Action', $autoload);
  77. }
  78. public function testAutoloadGetFilePath()
  79. {
  80. $autoload = require(self::$file);
  81. $this->assertNotEmpty(Load::getFilePath('Registry'));
  82. }
  83. /**
  84. * @TODO: Load::getFilePath - check for wrong index
  85. * @expectedException PHPUnit_Framework_Error
  86. */
  87. public function testAutoloadGetFilePathNullIndex()
  88. {
  89. $autoload = require(self::$file);
  90. $this->assertNotEmpty(Load::getFilePath('anton'));
  91. }
  92. public static function tearDownAfterClass()
  93. {
  94. if (file_exists(self::$file)) {
  95. unlink(self::$file);
  96. }
  97. foreach (self::$inc_dirs as $dir => $is_exist) {
  98. if (!$is_exist) {
  99. rmdir($dir);
  100. }
  101. }
  102. rmdir(PATH . '/' . APP);
  103. }
  104. }