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