PhpFileLoaderTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Routing\Tests\Loader;
  11. use Symfony\Component\Config\FileLocator;
  12. use Symfony\Component\Routing\Loader\PhpFileLoader;
  13. class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
  14. {
  15. protected function setUp()
  16. {
  17. if (!class_exists('Symfony\Component\Config\FileLocator')) {
  18. $this->markTestSkipped('The "Config" component is not available');
  19. }
  20. }
  21. public function testSupports()
  22. {
  23. $loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
  24. $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
  25. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  26. $this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
  27. $this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
  28. }
  29. public function testLoadWithRoute()
  30. {
  31. $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
  32. $routeCollection = $loader->load('validpattern.php');
  33. $routes = $routeCollection->all();
  34. $this->assertCount(2, $routes, 'Two routes are loaded');
  35. $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
  36. foreach ($routes as $route) {
  37. $this->assertSame('/blog/{slug}', $route->getPath());
  38. $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
  39. $this->assertSame('{locale}.example.com', $route->getHost());
  40. $this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
  41. $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
  42. $this->assertEquals(array('https'), $route->getSchemes());
  43. }
  44. }
  45. }