diff --git a/src/Core/Attributes/ServeSchema.php b/src/Core/Attributes/ServeSchema.php new file mode 100644 index 0000000..8affa14 --- /dev/null +++ b/src/Core/Attributes/ServeSchema.php @@ -0,0 +1,18 @@ +getAttributes(ServeSchema::class))) + ->map(fn (ReflectionAttribute $attribute): array => $attribute->getArguments()) + ->flatten() + ->all(); + } /** * Server constructor. diff --git a/tests/Unit/Server/ServerWithAttributesTest.php b/tests/Unit/Server/ServerWithAttributesTest.php new file mode 100644 index 0000000..0abfd06 --- /dev/null +++ b/tests/Unit/Server/ServerWithAttributesTest.php @@ -0,0 +1,90 @@ +app = $this->createMock(Application::class); + $this->config = $this->createMock(ConfigRepository::class); + $this->resolver = new AppResolver(fn() => $this->app); + $this->repository = new ServerRepository($this->resolver); + } + + /** + * @return void + */ + public function test(): void + { + $expected = $this->willMakeServer($name = 'v1'); + $actual = $this->repository->server($name); + + $this->assertInstanceOf(TestServerWithServeSchemaAttribute::class, $actual); + $this->assertEquals($expected, $actual); + $this->assertTrue($actual->schemas()->existsForModel(TestSchema::$model)); + } + + + /** + * @param string $name + * @param string $class + * @return TestServer + */ + private function willMakeServer(string $name, string $class = TestServerWithServeSchemaAttribute::class): TestServerWithServeSchemaAttribute + { + $this->app + ->method('make') + ->with(ConfigRepository::class) + ->willReturn($this->config); + + $this->config + ->expects($this->once()) + ->method('get') + ->with("jsonapi.servers.{$name}") + ->willReturn($class); + + return new TestServerWithServeSchemaAttribute($this->resolver, $name); + } +} diff --git a/tests/Unit/Server/TestSchema.php b/tests/Unit/Server/TestSchema.php new file mode 100644 index 0000000..0488a56 --- /dev/null +++ b/tests/Unit/Server/TestSchema.php @@ -0,0 +1,20 @@ +