RouteLoaderTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. class RouteLoaderTest extends PHPUnit_Framework_TestCase {
  3. public function tearDown()
  4. {
  5. $this->rrmdir(APP_PATH.'routes');
  6. }
  7. public function testRouteArrayShouldBeReturnedWhenUsingSingleRoutesFile()
  8. {
  9. $routes = System\Router::load('test');
  10. $this->assertEquals(count($routes), 1);
  11. $this->assertArrayHasKey('GET /', $routes);
  12. $this->assertTrue(is_callable($routes['GET /']));
  13. }
  14. public function testRouteLoaderReturnsHomeRoutesWhenItIsOnlyFileInRoutesDirectory()
  15. {
  16. mkdir(APP_PATH.'routes', 0777);
  17. file_put_contents(APP_PATH.'routes/home.php', "<?php return array('GET /' => function() {return '/';}); ?>", LOCK_EX);
  18. $this->assertEquals(count(System\Router::load('')), 1);
  19. }
  20. public function testRouteLoaderWithRoutesDirectory()
  21. {
  22. mkdir(APP_PATH.'routes', 0777);
  23. file_put_contents(APP_PATH.'routes/user.php', "<?php return array('GET /user' => function() {return '/user';}); ?>", LOCK_EX);
  24. $routes = System\Router::load('user/home');
  25. $this->assertEquals(count($routes), 2);
  26. $this->assertArrayHasKey('GET /', $routes);
  27. $this->assertArrayHasKey('GET /user', $routes);
  28. $this->assertTrue(is_callable($routes['GET /']));
  29. $this->assertTrue(is_callable($routes['GET /user']));
  30. }
  31. /**
  32. * Recursively Remove A Directory.
  33. */
  34. public function rrmdir($dir)
  35. {
  36. if (is_dir($dir))
  37. {
  38. $objects = scandir($dir);
  39. foreach ($objects as $object)
  40. {
  41. if ($object != "." && $object != "..")
  42. {
  43. if (filetype($dir."/".$object) == "dir") rrmdir($dir."/".$object); else unlink($dir."/".$object);
  44. }
  45. }
  46. reset($objects);
  47. rmdir($dir);
  48. }
  49. }
  50. }