|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +namespace Chimera\Mapping\Tests\Functional\Routing; |
| 5 | + |
| 6 | +use Chimera\Mapping\Routing\SimpleEndpoint; |
| 7 | +use Chimera\Mapping\Tests\Functional\TestCase; |
| 8 | +use Doctrine\Common\Annotations\AnnotationException; |
| 9 | +use function assert; |
| 10 | + |
| 11 | +final class SimpleEndpointTest extends TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @test |
| 15 | + * |
| 16 | + * @covers \Chimera\Mapping\Routing\SimpleEndpoint |
| 17 | + * @covers \Chimera\Mapping\Routing\SimpleEndpoint |
| 18 | + * @covers \Chimera\Mapping\Reader |
| 19 | + */ |
| 20 | + public function defaultValueShouldBeConfiguredProperly(): void |
| 21 | + { |
| 22 | + $annotation = $this->readAnnotation(FetchBookRequestHandler::class, SimpleEndpoint::class); |
| 23 | + assert($annotation instanceof SimpleEndpoint || $annotation === null); |
| 24 | + |
| 25 | + self::assertInstanceOf(SimpleEndpoint::class, $annotation); |
| 26 | + self::assertSame('/books/{id}', $annotation->path); |
| 27 | + self::assertSame(['GET'], $annotation->methods); |
| 28 | + self::assertSame('books.fetch', $annotation->name); |
| 29 | + self::assertNull($annotation->app); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * @test |
| 34 | + * |
| 35 | + * @covers \Chimera\Mapping\Routing\SimpleEndpoint |
| 36 | + * @covers \Chimera\Mapping\Routing\SimpleEndpoint |
| 37 | + * @covers \Chimera\Mapping\Reader |
| 38 | + */ |
| 39 | + public function propertiesShouldBeConfiguredProperly(): void |
| 40 | + { |
| 41 | + $annotation = $this->readAnnotation(FindBooksRequestHandler::class, SimpleEndpoint::class); |
| 42 | + assert($annotation instanceof SimpleEndpoint || $annotation === null); |
| 43 | + |
| 44 | + self::assertInstanceOf(SimpleEndpoint::class, $annotation); |
| 45 | + self::assertSame('/books', $annotation->path); |
| 46 | + self::assertSame(['GET'], $annotation->methods); |
| 47 | + self::assertSame('books.find', $annotation->name); |
| 48 | + self::assertSame('my-app', $annotation->app); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @test |
| 53 | + * |
| 54 | + * @covers \Chimera\Mapping\Routing\SimpleEndpoint |
| 55 | + * @covers \Chimera\Mapping\Routing\SimpleEndpoint |
| 56 | + * @covers \Chimera\Mapping\Reader |
| 57 | + */ |
| 58 | + public function exceptionShouldBeRaisedWhenRequiredPropertiesAreMissing(): void |
| 59 | + { |
| 60 | + $this->expectException(AnnotationException::class); |
| 61 | + $this->readAnnotation(FindAuthorsRequestHandler::class, SimpleEndpoint::class); |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +/** |
| 66 | + * @SimpleEndpoint("/books/{id}", name="books.fetch") |
| 67 | +*/ |
| 68 | +final class FetchBookRequestHandler |
| 69 | +{ |
| 70 | +} |
| 71 | + |
| 72 | +/** |
| 73 | + * @SimpleEndpoint(path="/books", name="books.find", app="my-app") |
| 74 | + */ |
| 75 | +final class FindBooksRequestHandler |
| 76 | +{ |
| 77 | +} |
| 78 | + |
| 79 | +/** |
| 80 | + * @SimpleEndpoint |
| 81 | + */ |
| 82 | +final class FindAuthorsRequestHandler |
| 83 | +{ |
| 84 | +} |
0 commit comments