From 9eb11fca682b5984f9dabc12cd57e042991d6818 Mon Sep 17 00:00:00 2001 From: Ramon Rietdijk Date: Fri, 25 Nov 2022 11:35:43 +0100 Subject: [PATCH 1/2] Added null coalescing assignment operator for the base resource --- src/OData/BaseResource.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OData/BaseResource.php b/src/OData/BaseResource.php index 44d758a..e4d2a05 100644 --- a/src/OData/BaseResource.php +++ b/src/OData/BaseResource.php @@ -28,8 +28,8 @@ abstract class BaseResource implements ArrayAccess, Arrayable public function __construct(?string $connection = null, ?string $endpoint = null) { - $this->connection = $connection ?? config('dynamics.connection'); - $this->endpoint = $endpoint ?? config('dynamics.resources.'.static::class, Str::afterLast(static::class, '\\')); + $this->connection ??= $connection ?? config('dynamics.connection'); + $this->endpoint ??= $endpoint ?? config('dynamics.resources.'.static::class, Str::afterLast(static::class, '\\')); } public static function new(?string $connection = null, ?string $endpoint = null): static From 1b25482d8ba8669ca8260d91ee83a66b1a22ef42 Mon Sep 17 00:00:00 2001 From: Ramon Rietdijk Date: Fri, 25 Nov 2022 11:45:05 +0100 Subject: [PATCH 2/2] Updated test --- tests/Fakes/OData/FakeResource.php | 16 ++++++++++++++ tests/OData/BaseResourceTest.php | 34 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 tests/Fakes/OData/FakeResource.php diff --git a/tests/Fakes/OData/FakeResource.php b/tests/Fakes/OData/FakeResource.php new file mode 100644 index 0000000..ee6b723 --- /dev/null +++ b/tests/Fakes/OData/FakeResource.php @@ -0,0 +1,16 @@ +set('dynamics.resources', [ + Customer::class => '::customer-endpoint::', + ]); + config()->set('dynamics.connections.::default::', [ 'base_url' => '::base_url::', 'company' => '::company::', @@ -44,6 +49,14 @@ public function it_can_get_the_default_connection(): void $this->assertEquals('::default::', $page->connection); } + /** @test */ + public function it_can_get_the_default_endpoint(): void + { + $page = new Customer(); + + $this->assertEquals('::customer-endpoint::', $page->endpoint); + } + /** @test */ public function it_can_set_the_connection(): void { @@ -55,4 +68,25 @@ public function it_can_set_the_connection(): void $this->assertEquals('::other-connection::', $page->connection); } + + /** @test */ + public function it_can_set_the_endpoint(): void + { + $page = new Customer(null, '::other-endpoint::'); + + $this->assertEquals('::other-endpoint::', $page->endpoint); + + $page = Customer::new(null, '::other-endpoint::'); + + $this->assertEquals('::other-endpoint::', $page->endpoint); + } + + /** @test */ + public function it_can_force_a_connection_and_endpoint(): void + { + $resource = FakeResource::new(); + + $this->assertEquals('::fake-connection::', $resource->connection); + $this->assertEquals('::fake-endpoint::', $resource->endpoint); + } }