AnnotationClassLoaderTest.php 2.4 KB

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