AnnotationClassLoaderTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Tests\Component\Routing\Loader;
  11. use Symfony\Component\Config\Loader\LoaderResolver;
  12. use Symfony\Component\Routing\Loader\AnnotationClassLoader;
  13. use Symfony\Component\Routing\Route;
  14. use Symfony\Component\Routing\RouteCollection;
  15. require_once __DIR__.'/../Fixtures/AnnotatedClasses/AbstractClass.php';
  16. require_once __DIR__.'/AbstractAnnotationLoaderTest.php';
  17. class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
  18. {
  19. protected $loader;
  20. public function setUp()
  21. {
  22. parent::setUp();
  23. $this->loader = $this->getClassLoader($this->getReader());
  24. }
  25. /**
  26. * @expectedException \InvalidArgumentException
  27. */
  28. public function testLoadMissingClass()
  29. {
  30. $this->loader->load('MissingClass');
  31. }
  32. /**
  33. * @expectedException \InvalidArgumentException
  34. */
  35. public function testLoadAbstractClass()
  36. {
  37. $this->loader->load('Symfony\Tests\Component\Routing\Fixtures\AnnotatedClasses\AbstractClass');
  38. }
  39. /**
  40. * @covers Symfony\Component\Routing\Loader\AnnotationClassLoader::supports
  41. * @dataProvider provideTestSupportsChecksResource
  42. */
  43. public function testSupportsChecksResource($resource, $expectedSupports)
  44. {
  45. $this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable');
  46. }
  47. public function provideTestSupportsChecksResource()
  48. {
  49. return array(
  50. array('class', true),
  51. array('\fully\qualified\class\name', true),
  52. array('namespaced\class\without\leading\slash', true),
  53. array('ÿClassWithLegalSpecialCharacters', true),
  54. array('5', false),
  55. array('foo.foo', false),
  56. array(null, false),
  57. );
  58. }
  59. /**
  60. * @covers Symfony\Component\Routing\Loader\AnnotationClassLoader::supports
  61. */
  62. public function testSupportsChecksTypeIfSpecified()
  63. {
  64. $this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified');
  65. $this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
  66. }
  67. }