From 180ae5a49cee52b5c4d774869c089aef6bdfebef Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 20 Sep 2023 00:54:51 +0100 Subject: [PATCH] Add config options for singular/plurals --- src/Resource.php | 4 ++-- tests/ResourceTest.php | 52 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/Resource.php b/src/Resource.php index 30bfbaab..a12f9b6f 100644 --- a/src/Resource.php +++ b/src/Resource.php @@ -103,12 +103,12 @@ public function name() public function singular(): string { - return Str::singular($this->name); + return $this->config()->get('singular') ?? Str::singular($this->name); } public function plural(): string { - return Str::plural($this->name); + return $this->config()->get('plural') ?? Str::plural($this->name); } public function blueprint() diff --git a/tests/ResourceTest.php b/tests/ResourceTest.php index 63ca86a7..dd5bdcd8 100644 --- a/tests/ResourceTest.php +++ b/tests/ResourceTest.php @@ -71,4 +71,56 @@ public function can_get_eager_loading_relations_as_defined_in_config() $this->assertContains('author', $eagerLoadingRelations->toArray()); $this->assertNotContains('runwayUri', $eagerLoadingRelations->toArray()); } + + /** @test */ + public function can_get_generated_singular() + { + Runway::discoverResources(); + + $resource = Runway::findResource('post'); + + $singular = $resource->singular(); + + $this->assertSame($singular, 'Post'); + } + + /** @test */ + public function can_get_configured_singular() + { + Config::set('runway.resources.DoubleThreeDigital\Runway\Tests\Post.singular', 'Bibliothek'); + + Runway::discoverResources(); + + $resource = Runway::findResource('post'); + + $singular = $resource->singular(); + + $this->assertSame($singular, 'Bibliothek'); + } + + /** @test */ + public function can_get_generated_plural() + { + Runway::discoverResources(); + + $resource = Runway::findResource('post'); + + $plural = $resource->plural(); + + $this->assertSame($plural, 'Posts'); + } + + /** @test */ + public function can_get_configured_plural() + { + Config::set('runway.resources.DoubleThreeDigital\Runway\Tests\Post.plural', 'Bibliotheken'); + + Runway::discoverResources(); + + $resource = Runway::findResource('post'); + + $plural = $resource->plural(); + + $this->assertSame($plural, 'Bibliotheken'); + } }