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.

86 lines
2.3 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-..
  8. *
  9. * Unit tests for AutoloadBuilder class
  10. */
  11. require_once dirname(__FILE__) . '/../../util/AutoloadBuilder.php';
  12. /**
  13. * @TODO: AutoloadBuilder - fix writing to file: construct array first, write to file next - atomic operation
  14. */
  15. class AutoloadBuilderTest extends PHPUnit_Framework_TestCase
  16. {
  17. private static $inc_dirs = array();
  18. private static $file;
  19. /**
  20. * @TODO: Load->buildAutoload() - uses two paths - PATH . '/' . APP . '/src' and PATH . '/lib' those are not checked. Can couse error.
  21. * @expectedException UnexpectedValueException
  22. * @expectedException PHPUnit_Framework_Error
  23. */
  24. public static function setUpBeforeClass()
  25. {
  26. if (!defined('PATH')) {
  27. define('PATH', realpath(dirname(__FILE__) . '/../../../..'));
  28. }
  29. // default application name
  30. if (!defined('APP')) {
  31. define('APP', 'lib/core/tests/face');
  32. }
  33. self::$file = PATH . '/' . APP . '/cache/autoload.php';
  34. // value - if dir exists (to delete it if it was created), default true
  35. self::$inc_dirs[PATH . '/' . APP . '/src'] = true;
  36. self::$inc_dirs[PATH . '/' . APP . '/cache'] = true;
  37. self::$inc_dirs[PATH . '/lib'] = true;
  38. foreach (self::$inc_dirs as $dir => &$is_exist) {
  39. if (!file_exists($dir)) {
  40. $is_exist = false;
  41. mkdir($dir, 0777, true);
  42. }
  43. }
  44. }
  45. /**
  46. * @TODO: AutoloadBuilder - check input params: string for filename, array for dirs
  47. * @expectedException PHPUnit_Framework_Error
  48. */
  49. public function testBuildParams()
  50. {
  51. $autoload = self::$file;
  52. $dirs = 'string';
  53. $builder = new AutoloadBuilder($autoload, $dirs);
  54. $builder->build();
  55. }
  56. public function testAutoloadFileExists()
  57. {
  58. $this->assertFileExists(self::$file);
  59. }
  60. public static function tearDownAfterClass()
  61. {
  62. if (file_exists(self::$file)) {
  63. unlink(self::$file);
  64. }
  65. foreach (self::$inc_dirs as $dir => $is_exist) {
  66. if (!$is_exist) {
  67. rmdir($dir);
  68. }
  69. }
  70. rmdir(PATH . '/' . APP);
  71. }
  72. }