diff --git a/.gitignore b/.gitignore index 81b9258..3eeba7a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ composer.lock phpunit.xml vendor +.phpunit.result.cache +.phpunit.cache/test-results diff --git a/composer.json b/composer.json index 527d778..97a5fde 100644 --- a/composer.json +++ b/composer.json @@ -10,9 +10,9 @@ } ], "require": { - "php": "^7.2.5|^8.0", - "illuminate/support": "^7.0|^8.0|^9.0|^10.0", - "illuminate/filesystem": "^7.0|^8.0|^9.0|^10.0", + "php": "^8.0", + "illuminate/support": "^8.0|^9.0|^10.0|^11.0", + "illuminate/filesystem": "^8.0|^9.0|^10.0|^11.0", "doctrine/annotations": "~1.2 | ^2.0", "phpdocumentor/reflection-docblock": "^3.1 || ^4.1 || ^5" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4196eb5..938cd60 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,27 +1,13 @@ - - - - ./tests - - - - - ./src - - + + + + ./tests + + + + + ./src + + diff --git a/src/Blueprint.php b/src/Blueprint.php index 0f2e46b..94519f2 100644 --- a/src/Blueprint.php +++ b/src/Blueprint.php @@ -5,13 +5,14 @@ use Dingo\Blueprint\Annotation\Attribute; use Dingo\Blueprint\Annotation\NamedType; use Dingo\Blueprint\Annotation\Parameter; +use Doctrine\Common\Annotations\AnnotationReader; use ReflectionClass; use RuntimeException; use Illuminate\Support\Str; use Illuminate\Support\Collection; use Illuminate\Filesystem\Filesystem; use Doctrine\Common\Annotations\AnnotationRegistry; -use Doctrine\Common\Annotations\SimpleAnnotationReader; +use PHPUnit\Metadata\Parser\AnnotationParser; class Blueprint { @@ -24,7 +25,7 @@ class Blueprint /** * Simple annotation reader instance. * - * @var \Doctrine\Common\Annotations\SimpleAnnotationReader + * @var \Doctrine\Common\Annotations\AnnotationReader */ protected $reader; @@ -45,38 +46,15 @@ class Blueprint /** * Create a new generator instance. * - * @param \Doctrine\Common\Annotations\SimpleAnnotationReader $reader + * @param \Doctrine\Common\Annotations\AnnotationReader $reader * @param \Illuminate\Filesystem\Filesystem $files * * @return void */ - public function __construct(SimpleAnnotationReader $reader, Filesystem $files) + public function __construct(AnnotationReader $reader, Filesystem $files) { $this->reader = $reader; $this->files = $files; - - $this->registerAnnotationLoader(); - } - - /** - * Register the annotation loader. - * - * @return void - */ - protected function registerAnnotationLoader() - { - $this->reader->addNamespace('Dingo\\Blueprint\\Annotation'); - $this->reader->addNamespace('Dingo\\Blueprint\\Annotation\\Method'); - - AnnotationRegistry::registerLoader(function ($class) { - $path = __DIR__.'/'.str_replace(['Dingo\\Blueprint\\', '\\'], ['', DIRECTORY_SEPARATOR], $class).'.php'; - - if (file_exists($path)) { - require_once $path; - - return true; - } - }); } /** diff --git a/tests/BlueprintTest.php b/tests/BlueprintTest.php index 7381f65..32ec5f8 100644 --- a/tests/BlueprintTest.php +++ b/tests/BlueprintTest.php @@ -3,10 +3,10 @@ namespace Dingo\Blueprint\Tests; use Dingo\Blueprint\Blueprint; +use Doctrine\Common\Annotations\AnnotationReader; use PHPUnit\Framework\TestCase; use Illuminate\Support\Collection; use Illuminate\Filesystem\Filesystem; -use Doctrine\Common\Annotations\SimpleAnnotationReader; class BlueprintTest extends TestCase { @@ -14,7 +14,7 @@ public function testGeneratingBlueprintForSingleResource() { $resources = new Collection([new Stubs\UsersResourceStub]); - $blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem); + $blueprint = new Blueprint(new AnnotationReader(), new Filesystem); $expected = <<<'EOT' FORMAT: 1A @@ -106,14 +106,17 @@ public function testGeneratingBlueprintForSingleResource() } EOT; - $this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null)); + $this->assertEquals( + trim($expected), + $blueprint->generate($resources, 'testing', 'v1', null) + ); } public function testGeneratingBlueprintForMultipleResourcesWithVersionOne() { $resources = new Collection([new Stubs\UsersResourceStub, new Stubs\UserPhotosResourceStub]); - $blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem); + $blueprint = new Blueprint(new AnnotationReader(), new Filesystem); $expected = <<<'EOT' FORMAT: 1A @@ -265,14 +268,17 @@ public function testGeneratingBlueprintForMultipleResourcesWithVersionOne() } EOT; - $this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null)); + $this->assertEquals( + trim($expected), + $blueprint->generate($resources, 'testing', 'v1', null) + ); } public function testGeneratingBlueprintForMultipleResourcesWithVersionTwo() { $resources = new Collection([new Stubs\UsersResourceStub, new Stubs\UserPhotosResourceStub]); - $blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem); + $blueprint = new Blueprint(new AnnotationReader(), new Filesystem); $expected = <<<'EOT' FORMAT: 1A @@ -466,14 +472,17 @@ public function testGeneratingBlueprintForMultipleResourcesWithVersionTwo() } EOT; - $this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v2', null)); + $this->assertEquals( + trim($expected), + $blueprint->generate($resources, 'testing', 'v2', null) + ); } public function testGeneratingSimpleBlueprints() { $resources = new Collection([new Stubs\ActivityController]); - $blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem); + $blueprint = new Blueprint(new AnnotationReader(), new Filesystem); $expected = <<<'EOT' FORMAT: 1A @@ -492,7 +501,7 @@ public function testGeneratingBlueprintOverview() { $resources = new Collection([new Stubs\ActivityController]); - $blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem); + $blueprint = new Blueprint(new AnnotationReader(), new Filesystem); $expected = <<<'EOT' FORMAT: 1A @@ -506,8 +515,9 @@ public function testGeneratingBlueprintOverview() ## Show all activities. [GET /activity] EOT; - $this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null, __DIR__.'/Files/overview.apib')); - - + $this->assertEquals( + trim($expected), + $blueprint->generate($resources, 'testing', 'v1', null, __DIR__.'/Files/overview.apib') + ); } } diff --git a/tests/LaravelIntegrationTest.php b/tests/LaravelIntegrationTest.php index 57da07c..c48bdd5 100644 --- a/tests/LaravelIntegrationTest.php +++ b/tests/LaravelIntegrationTest.php @@ -2,9 +2,9 @@ namespace Dingo\Blueprint { + use Doctrine\Common\Annotations\AnnotationReader; use Illuminate\Support\Collection; use Illuminate\Filesystem\Filesystem; - use Doctrine\Common\Annotations\SimpleAnnotationReader; use PHPUnit\Framework\TestCase; class LaravelIntegrationTest extends TestCase @@ -23,18 +23,24 @@ public function testGetAnnotationByTypeInLaravel52x() { $resources = new Collection([new Tests\Stubs\ActivityController]); - $blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem); + $blueprint = new Blueprint(new AnnotationReader(), new Filesystem); - $this->assertEquals(trim($this->simpleExample), $blueprint->generate($resources, 'testing', 'v1', null)); + $this->assertEquals( + trim($this->simpleExample), + $blueprint->generate($resources, 'testing', 'v1', null) + ); } public function testGetAnnotationByTypeInLaravel53x() { $resources = new Collection([new Tests\Stubs\ActivityController]); - $blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem); + $blueprint = new Blueprint(new AnnotationReader, new Filesystem); - $this->assertEquals(trim($this->simpleExample), $blueprint->generate($resources, 'testing', 'v1', null)); + $this->assertEquals( + trim($this->simpleExample), + $blueprint->generate($resources, 'testing', 'v1', null) + ); } } diff --git a/tests/Stubs/ActivityController.php b/tests/Stubs/ActivityController.php index c8f6585..0506cd8 100644 --- a/tests/Stubs/ActivityController.php +++ b/tests/Stubs/ActivityController.php @@ -2,6 +2,9 @@ namespace Dingo\Blueprint\Tests\Stubs; +use Dingo\Blueprint\Annotation\Resource; +use Dingo\Blueprint\Annotation\Method\Get; + /** * @Resource("Activity") */ diff --git a/tests/Stubs/UserPhotosResourceStub.php b/tests/Stubs/UserPhotosResourceStub.php index 46a5b6f..7a558f4 100644 --- a/tests/Stubs/UserPhotosResourceStub.php +++ b/tests/Stubs/UserPhotosResourceStub.php @@ -2,6 +2,20 @@ namespace Dingo\Blueprint\Tests\Stubs; +use Dingo\Blueprint\Annotation\Resource; +use Dingo\Blueprint\Annotation\Method\Get; +use Dingo\Blueprint\Annotation\Method\Post; +use Dingo\Blueprint\Annotation\Parameter; +use Dingo\Blueprint\Annotation\Parameters; +use Dingo\Blueprint\Annotation\Request; +use Dingo\Blueprint\Annotation\Response; +use Dingo\Blueprint\Annotation\Transaction; +use Dingo\Blueprint\Annotation\Member; +use Dingo\Blueprint\Annotation\Versions; +use Dingo\Blueprint\Annotation\Attribute; +use Dingo\Blueprint\Annotation\Attributes; +use Dingo\Blueprint\Annotation\Method\Delete; + /** * User Photos Resource. * diff --git a/tests/Stubs/UsersResourceStub.php b/tests/Stubs/UsersResourceStub.php index ddb55d5..546739b 100644 --- a/tests/Stubs/UsersResourceStub.php +++ b/tests/Stubs/UsersResourceStub.php @@ -2,6 +2,16 @@ namespace Dingo\Blueprint\Tests\Stubs; +use Dingo\Blueprint\Annotation\Attribute; +use Dingo\Blueprint\Annotation\Resource; +use Dingo\Blueprint\Annotation\Method\Get; +use Dingo\Blueprint\Annotation\Method\Post; +use Dingo\Blueprint\Annotation\Parameter; +use Dingo\Blueprint\Annotation\Parameters; +use Dingo\Blueprint\Annotation\Request; +use Dingo\Blueprint\Annotation\Response; +use Dingo\Blueprint\Annotation\Transaction; + /** * Users Resource. *