Skip to content

Commit

Permalink
Merge pull request #93 from nasrulhazim/feature/laravel-11
Browse files Browse the repository at this point in the history
Added Feature to Support Laravel 11
  • Loading branch information
specialtactics authored May 9, 2024
2 parents 3ad4885 + aa596c9 commit 9d67ce6
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 72 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
composer.lock
phpunit.xml
vendor
.phpunit.result.cache
.phpunit.cache/test-results
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
36 changes: 11 additions & 25 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
syntaxCheck="true"
verbose="true"
>
<testsuites>
<testsuite name="API Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<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">
<testsuites>
<testsuite name="API Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
32 changes: 5 additions & 27 deletions src/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -24,7 +25,7 @@ class Blueprint
/**
* Simple annotation reader instance.
*
* @var \Doctrine\Common\Annotations\SimpleAnnotationReader
* @var \Doctrine\Common\Annotations\AnnotationReader
*/
protected $reader;

Expand All @@ -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;
}
});
}

/**
Expand Down
34 changes: 22 additions & 12 deletions tests/BlueprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
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
{
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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')
);
}
}
16 changes: 11 additions & 5 deletions tests/LaravelIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
);
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/Stubs/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Dingo\Blueprint\Tests\Stubs;

use Dingo\Blueprint\Annotation\Resource;
use Dingo\Blueprint\Annotation\Method\Get;

/**
* @Resource("Activity")
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/Stubs/UserPhotosResourceStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Stubs/UsersResourceStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 9d67ce6

Please sign in to comment.