Skip to content

Commit 9d67ce6

Browse files
Merge pull request #93 from nasrulhazim/feature/laravel-11
Added Feature to Support Laravel 11
2 parents 3ad4885 + aa596c9 commit 9d67ce6

File tree

9 files changed

+81
-72
lines changed

9 files changed

+81
-72
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
composer.lock
22
phpunit.xml
33
vendor
4+
.phpunit.result.cache
5+
.phpunit.cache/test-results

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.2.5|^8.0",
14-
"illuminate/support": "^7.0|^8.0|^9.0|^10.0",
15-
"illuminate/filesystem": "^7.0|^8.0|^9.0|^10.0",
13+
"php": "^8.0",
14+
"illuminate/support": "^8.0|^9.0|^10.0|^11.0",
15+
"illuminate/filesystem": "^8.0|^9.0|^10.0|^11.0",
1616
"doctrine/annotations": "~1.2 | ^2.0",
1717
"phpdocumentor/reflection-docblock": "^3.1 || ^4.1 || ^5"
1818
},

phpunit.xml.dist

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
beStrictAboutTestsThatDoNotTestAnything="true"
5-
beStrictAboutOutputDuringTests="true"
6-
bootstrap="vendor/autoload.php"
7-
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
processIsolation="false"
12-
stopOnError="false"
13-
stopOnFailure="false"
14-
syntaxCheck="true"
15-
verbose="true"
16-
>
17-
<testsuites>
18-
<testsuite name="API Test Suite">
19-
<directory suffix="Test.php">./tests</directory>
20-
</testsuite>
21-
</testsuites>
22-
<filter>
23-
<whitelist processUncoveredFilesFromWhitelist="true">
24-
<directory suffix=".php">./src</directory>
25-
</whitelist>
26-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache">
3+
<testsuites>
4+
<testsuite name="API Test Suite">
5+
<directory suffix="Test.php">./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">./src</directory>
11+
</include>
12+
</source>
2713
</phpunit>

src/Blueprint.php

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
use Dingo\Blueprint\Annotation\Attribute;
66
use Dingo\Blueprint\Annotation\NamedType;
77
use Dingo\Blueprint\Annotation\Parameter;
8+
use Doctrine\Common\Annotations\AnnotationReader;
89
use ReflectionClass;
910
use RuntimeException;
1011
use Illuminate\Support\Str;
1112
use Illuminate\Support\Collection;
1213
use Illuminate\Filesystem\Filesystem;
1314
use Doctrine\Common\Annotations\AnnotationRegistry;
14-
use Doctrine\Common\Annotations\SimpleAnnotationReader;
15+
use PHPUnit\Metadata\Parser\AnnotationParser;
1516

1617
class Blueprint
1718
{
@@ -24,7 +25,7 @@ class Blueprint
2425
/**
2526
* Simple annotation reader instance.
2627
*
27-
* @var \Doctrine\Common\Annotations\SimpleAnnotationReader
28+
* @var \Doctrine\Common\Annotations\AnnotationReader
2829
*/
2930
protected $reader;
3031

@@ -45,38 +46,15 @@ class Blueprint
4546
/**
4647
* Create a new generator instance.
4748
*
48-
* @param \Doctrine\Common\Annotations\SimpleAnnotationReader $reader
49+
* @param \Doctrine\Common\Annotations\AnnotationReader $reader
4950
* @param \Illuminate\Filesystem\Filesystem $files
5051
*
5152
* @return void
5253
*/
53-
public function __construct(SimpleAnnotationReader $reader, Filesystem $files)
54+
public function __construct(AnnotationReader $reader, Filesystem $files)
5455
{
5556
$this->reader = $reader;
5657
$this->files = $files;
57-
58-
$this->registerAnnotationLoader();
59-
}
60-
61-
/**
62-
* Register the annotation loader.
63-
*
64-
* @return void
65-
*/
66-
protected function registerAnnotationLoader()
67-
{
68-
$this->reader->addNamespace('Dingo\\Blueprint\\Annotation');
69-
$this->reader->addNamespace('Dingo\\Blueprint\\Annotation\\Method');
70-
71-
AnnotationRegistry::registerLoader(function ($class) {
72-
$path = __DIR__.'/'.str_replace(['Dingo\\Blueprint\\', '\\'], ['', DIRECTORY_SEPARATOR], $class).'.php';
73-
74-
if (file_exists($path)) {
75-
require_once $path;
76-
77-
return true;
78-
}
79-
});
8058
}
8159

8260
/**

tests/BlueprintTest.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,18 @@
33
namespace Dingo\Blueprint\Tests;
44

55
use Dingo\Blueprint\Blueprint;
6+
use Doctrine\Common\Annotations\AnnotationReader;
67
use PHPUnit\Framework\TestCase;
78
use Illuminate\Support\Collection;
89
use Illuminate\Filesystem\Filesystem;
9-
use Doctrine\Common\Annotations\SimpleAnnotationReader;
1010

1111
class BlueprintTest extends TestCase
1212
{
1313
public function testGeneratingBlueprintForSingleResource()
1414
{
1515
$resources = new Collection([new Stubs\UsersResourceStub]);
1616

17-
$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);
17+
$blueprint = new Blueprint(new AnnotationReader(), new Filesystem);
1818

1919
$expected = <<<'EOT'
2020
FORMAT: 1A
@@ -106,14 +106,17 @@ public function testGeneratingBlueprintForSingleResource()
106106
}
107107
EOT;
108108

109-
$this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null));
109+
$this->assertEquals(
110+
trim($expected),
111+
$blueprint->generate($resources, 'testing', 'v1', null)
112+
);
110113
}
111114

112115
public function testGeneratingBlueprintForMultipleResourcesWithVersionOne()
113116
{
114117
$resources = new Collection([new Stubs\UsersResourceStub, new Stubs\UserPhotosResourceStub]);
115118

116-
$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);
119+
$blueprint = new Blueprint(new AnnotationReader(), new Filesystem);
117120

118121
$expected = <<<'EOT'
119122
FORMAT: 1A
@@ -265,14 +268,17 @@ public function testGeneratingBlueprintForMultipleResourcesWithVersionOne()
265268
}
266269
EOT;
267270

268-
$this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null));
271+
$this->assertEquals(
272+
trim($expected),
273+
$blueprint->generate($resources, 'testing', 'v1', null)
274+
);
269275
}
270276

271277
public function testGeneratingBlueprintForMultipleResourcesWithVersionTwo()
272278
{
273279
$resources = new Collection([new Stubs\UsersResourceStub, new Stubs\UserPhotosResourceStub]);
274280

275-
$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);
281+
$blueprint = new Blueprint(new AnnotationReader(), new Filesystem);
276282

277283
$expected = <<<'EOT'
278284
FORMAT: 1A
@@ -466,14 +472,17 @@ public function testGeneratingBlueprintForMultipleResourcesWithVersionTwo()
466472
}
467473
EOT;
468474

469-
$this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v2', null));
475+
$this->assertEquals(
476+
trim($expected),
477+
$blueprint->generate($resources, 'testing', 'v2', null)
478+
);
470479
}
471480

472481
public function testGeneratingSimpleBlueprints()
473482
{
474483
$resources = new Collection([new Stubs\ActivityController]);
475484

476-
$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);
485+
$blueprint = new Blueprint(new AnnotationReader(), new Filesystem);
477486

478487
$expected = <<<'EOT'
479488
FORMAT: 1A
@@ -492,7 +501,7 @@ public function testGeneratingBlueprintOverview()
492501
{
493502
$resources = new Collection([new Stubs\ActivityController]);
494503

495-
$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);
504+
$blueprint = new Blueprint(new AnnotationReader(), new Filesystem);
496505

497506
$expected = <<<'EOT'
498507
FORMAT: 1A
@@ -506,8 +515,9 @@ public function testGeneratingBlueprintOverview()
506515
## Show all activities. [GET /activity]
507516
EOT;
508517

509-
$this->assertEquals(trim($expected), $blueprint->generate($resources, 'testing', 'v1', null, __DIR__.'/Files/overview.apib'));
510-
511-
518+
$this->assertEquals(
519+
trim($expected),
520+
$blueprint->generate($resources, 'testing', 'v1', null, __DIR__.'/Files/overview.apib')
521+
);
512522
}
513523
}

tests/LaravelIntegrationTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
namespace Dingo\Blueprint {
44

5+
use Doctrine\Common\Annotations\AnnotationReader;
56
use Illuminate\Support\Collection;
67
use Illuminate\Filesystem\Filesystem;
7-
use Doctrine\Common\Annotations\SimpleAnnotationReader;
88
use PHPUnit\Framework\TestCase;
99

1010
class LaravelIntegrationTest extends TestCase
@@ -23,18 +23,24 @@ public function testGetAnnotationByTypeInLaravel52x()
2323
{
2424
$resources = new Collection([new Tests\Stubs\ActivityController]);
2525

26-
$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);
26+
$blueprint = new Blueprint(new AnnotationReader(), new Filesystem);
2727

28-
$this->assertEquals(trim($this->simpleExample), $blueprint->generate($resources, 'testing', 'v1', null));
28+
$this->assertEquals(
29+
trim($this->simpleExample),
30+
$blueprint->generate($resources, 'testing', 'v1', null)
31+
);
2932
}
3033

3134
public function testGetAnnotationByTypeInLaravel53x()
3235
{
3336
$resources = new Collection([new Tests\Stubs\ActivityController]);
3437

35-
$blueprint = new Blueprint(new SimpleAnnotationReader, new Filesystem);
38+
$blueprint = new Blueprint(new AnnotationReader, new Filesystem);
3639

37-
$this->assertEquals(trim($this->simpleExample), $blueprint->generate($resources, 'testing', 'v1', null));
40+
$this->assertEquals(
41+
trim($this->simpleExample),
42+
$blueprint->generate($resources, 'testing', 'v1', null)
43+
);
3844
}
3945
}
4046

tests/Stubs/ActivityController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Dingo\Blueprint\Tests\Stubs;
44

5+
use Dingo\Blueprint\Annotation\Resource;
6+
use Dingo\Blueprint\Annotation\Method\Get;
7+
58
/**
69
* @Resource("Activity")
710
*/

tests/Stubs/UserPhotosResourceStub.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
namespace Dingo\Blueprint\Tests\Stubs;
44

5+
use Dingo\Blueprint\Annotation\Resource;
6+
use Dingo\Blueprint\Annotation\Method\Get;
7+
use Dingo\Blueprint\Annotation\Method\Post;
8+
use Dingo\Blueprint\Annotation\Parameter;
9+
use Dingo\Blueprint\Annotation\Parameters;
10+
use Dingo\Blueprint\Annotation\Request;
11+
use Dingo\Blueprint\Annotation\Response;
12+
use Dingo\Blueprint\Annotation\Transaction;
13+
use Dingo\Blueprint\Annotation\Member;
14+
use Dingo\Blueprint\Annotation\Versions;
15+
use Dingo\Blueprint\Annotation\Attribute;
16+
use Dingo\Blueprint\Annotation\Attributes;
17+
use Dingo\Blueprint\Annotation\Method\Delete;
18+
519
/**
620
* User Photos Resource.
721
*

tests/Stubs/UsersResourceStub.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
namespace Dingo\Blueprint\Tests\Stubs;
44

5+
use Dingo\Blueprint\Annotation\Attribute;
6+
use Dingo\Blueprint\Annotation\Resource;
7+
use Dingo\Blueprint\Annotation\Method\Get;
8+
use Dingo\Blueprint\Annotation\Method\Post;
9+
use Dingo\Blueprint\Annotation\Parameter;
10+
use Dingo\Blueprint\Annotation\Parameters;
11+
use Dingo\Blueprint\Annotation\Request;
12+
use Dingo\Blueprint\Annotation\Response;
13+
use Dingo\Blueprint\Annotation\Transaction;
14+
515
/**
616
* Users Resource.
717
*

0 commit comments

Comments
 (0)