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.

111 lines
2.9 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
  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() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
  18. * @expectedException UnexpectedValueException
  19. * @expectedException PHPUnit_Framework_Error
  20. */
  21. public static function setUpBeforeClass()
  22. {
  23. if (!defined('PATH')) {
  24. define('PATH', realpath(dirname(__FILE__) . '/../../..'));
  25. }
  26. // default application name
  27. if (!defined('APP')) {
  28. define('APP', 'lib/core/tests/face');
  29. }
  30. self::$file = PATH . '/' . APP . '/cache/autoload.php';
  31. // value - if dir exists (to delete it if it was created), default true
  32. self::$inc_dirs[PATH . '/' . APP . '/src'] = true;
  33. self::$inc_dirs[PATH . '/' . APP . '/cache'] = true;
  34. self::$inc_dirs[PATH . '/lib'] = true;
  35. foreach (self::$inc_dirs as $dir => &$is_exist) {
  36. if (!file_exists($dir)) {
  37. $is_exist = false;
  38. mkdir($dir, 0777, true);
  39. }
  40. }
  41. }
  42. public function testSetAutoLoadFrom()
  43. {
  44. // autoload
  45. Load::setAutoloadFrom(self::$file);
  46. $autoload = require(self::$file);
  47. $this->assertNotEmpty($autoload);
  48. }
  49. public function testAutoloadArrayExists()
  50. {
  51. $this->assertFileExists(self::$file);
  52. }
  53. /**
  54. * @TODO: Load - check if input file returns array
  55. */
  56. public function testFileForArray()
  57. {
  58. $autoload = require(self::$file);
  59. $this->assertInternalType('array', $autoload);
  60. }
  61. public function testAutoloadArrayNotEmpty()
  62. {
  63. $autoload = require(self::$file);
  64. $this->assertNotEmpty($autoload);
  65. $this->assertArrayHasKey('Action', $autoload);
  66. }
  67. public function testAutoloadGetFilePath()
  68. {
  69. $autoload = require(self::$file);
  70. $this->assertNotEmpty(Load::getFilePath('Registry'));
  71. }
  72. /**
  73. * @TODO: Load::getFilePath - check for wrong index
  74. * @expectedException PHPUnit_Framework_Error
  75. */
  76. public function testAutoloadGetFilePathNullIndex()
  77. {
  78. $autoload = require(self::$file);
  79. $this->assertNotEmpty(Load::getFilePath('anton'));
  80. }
  81. public static function tearDownAfterClass()
  82. {
  83. if (file_exists(self::$file)) {
  84. unlink(self::$file);
  85. }
  86. foreach (self::$inc_dirs as $dir => $is_exist) {
  87. if (!$is_exist) {
  88. rmdir($dir);
  89. }
  90. }
  91. rmdir(PATH . '/' . APP);
  92. }
  93. }