-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow users to use inspectors to further analyse the annotations
- Loading branch information
Showing
6 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zrnik\Zweist\System; | ||
|
||
use OpenApi\Annotations\AbstractAnnotation; | ||
|
||
interface OpenApiInspector | ||
{ | ||
/** | ||
* @param class-string $className | ||
* @param string $methodName | ||
* @param AbstractAnnotation $annotation | ||
* @return void | ||
*/ | ||
public function inspect(string $className, string $methodName, AbstractAnnotation $annotation): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zrnik\Zweist\Tests\ExampleApplication; | ||
|
||
use Exception; | ||
use OpenApi\Annotations\AbstractAnnotation; | ||
use Zrnik\Zweist\System\OpenApiInspector; | ||
|
||
class ExampleInspector implements OpenApiInspector | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function inspect(string $className, string $methodName, AbstractAnnotation $annotation): void | ||
{ | ||
/** | ||
* @noinspection ThrowRawExceptionInspection | ||
*/ | ||
throw new Exception(sprintf('%s called', self::class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Zrnik\Zweist\Tests; | ||
|
||
use DI\Container; | ||
use Exception; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Log\LoggerInterface; | ||
use Zrnik\PHPUnit\Exceptions; | ||
use Zrnik\Zweist\Tests\ExampleApplication\ExampleInspector; | ||
use Zrnik\Zweist\ZweistConfiguration; | ||
use Zrnik\Zweist\ZweistOpenApiGenerator; | ||
|
||
class InspectorTest extends TestCase | ||
{ | ||
use Exceptions; | ||
|
||
private Container $container; | ||
|
||
private ZweistConfiguration $zweistConfiguration; | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->container = new Container(); | ||
|
||
$this->container->set(LoggerInterface::class, $this->createMock(LoggerInterface::class)); | ||
|
||
$this->zweistConfiguration = new ZweistConfiguration( | ||
[ | ||
__DIR__ . '/ExampleApplication', | ||
], | ||
__DIR__ . '/../temp/OpenApi.json', | ||
__DIR__ . '/../temp/router.json', | ||
[ | ||
new ExampleInspector(), | ||
], | ||
); | ||
} | ||
|
||
public function testInspectorCalled(): void | ||
{ | ||
$zweistOpenApiGenerator = new ZweistOpenApiGenerator($this->zweistConfiguration, $this->container); | ||
|
||
/** @var Exception $exception */ | ||
$exception = $this->assertExceptionThrown( | ||
Exception::class, | ||
fn() => $zweistOpenApiGenerator->generate(), | ||
); | ||
|
||
$this->assertSame(sprintf('%s called', ExampleInspector::class), $exception->getMessage()); | ||
} | ||
} |