From bbab81f44481d87b4fe6d2696330dcacea214730 Mon Sep 17 00:00:00 2001 From: Vincent Bergeron Date: Fri, 11 Jul 2025 11:23:09 -0400 Subject: [PATCH 1/4] Add endpoint --- src/Endpoints/Provider.php | 11 ++++++++ tests/Endpoints/ProviderTest.php | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/Endpoints/Provider.php create mode 100644 tests/Endpoints/ProviderTest.php diff --git a/src/Endpoints/Provider.php b/src/Endpoints/Provider.php new file mode 100644 index 0000000..0a50762 --- /dev/null +++ b/src/Endpoints/Provider.php @@ -0,0 +1,11 @@ +getRequest("providers/{$provider}/metadata"); + } +} diff --git a/tests/Endpoints/ProviderTest.php b/tests/Endpoints/ProviderTest.php new file mode 100644 index 0000000..f14c014 --- /dev/null +++ b/tests/Endpoints/ProviderTest.php @@ -0,0 +1,44 @@ +client = Mockery::mock(Client::class); + $this->spinupwp = new SpinupWp('123', $this->client); + $this->endpoint = new Provider($this->spinupwp); + } + + public function test_metadata_request(): void + { + $this->client->shouldReceive('request')->once()->with('GET', 'providers/digitalocean/metadata', [])->andReturn( + new Response(200, [], json_encode(['regions' => [], 'sizes' => []])) + ); + + $result = $this->endpoint->metadata('digitalocean'); + $this->assertArrayHasKey('regions', $result); + $this->assertArrayHasKey('sizes', $result); + } +} From c132d8bb873d9e9af963e0337b2520d86142b695 Mon Sep 17 00:00:00 2001 From: Vincent Bergeron Date: Fri, 11 Jul 2025 11:26:23 -0400 Subject: [PATCH 2/4] Fix phpstan --- src/Resources/Resource.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index e112d53..711a7db 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -24,12 +24,12 @@ public function toArray(): array return $this->attributes; } - public function __get(string $name) + public function __get(string $name): mixed { return $this->attributes[$name] ?? null; } - public function __set(string $name, $value): void + public function __set(string $name, mixed $value): void { $this->attributes[$name] = $value; } From 86dd75f6c19408c892476dbb5daf037b5dd0fe6a Mon Sep 17 00:00:00 2001 From: Vincent Bergeron Date: Fri, 11 Jul 2025 11:29:06 -0400 Subject: [PATCH 3/4] use phpdoc --- src/Resources/Resource.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index 711a7db..4e0c44b 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -24,12 +24,18 @@ public function toArray(): array return $this->attributes; } - public function __get(string $name): mixed + /** + * @return mixed|null + */ + public function __get(string $name) { return $this->attributes[$name] ?? null; } - public function __set(string $name, mixed $value): void + /** + * @param mixed $value + */ + public function __set(string $name, $value): void { $this->attributes[$name] = $value; } From 2c546cca8c786e0c4dc797a4a780c43577f5bae9 Mon Sep 17 00:00:00 2001 From: Vincent Bergeron Date: Fri, 11 Jul 2025 11:32:12 -0400 Subject: [PATCH 4/4] Remove unused imports --- tests/Endpoints/ProviderTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/Endpoints/ProviderTest.php b/tests/Endpoints/ProviderTest.php index f14c014..0026761 100644 --- a/tests/Endpoints/ProviderTest.php +++ b/tests/Endpoints/ProviderTest.php @@ -7,13 +7,6 @@ use Mockery; use PHPUnit\Framework\TestCase; use SpinupWp\Endpoints\Provider; -use SpinupWp\Endpoints\Site; -use SpinupWp\Endpoints\SshKey; -use SpinupWp\Exceptions\NotFoundException; -use SpinupWp\Exceptions\RateLimitException; -use SpinupWp\Exceptions\UnauthorizedException; -use SpinupWp\Exceptions\ValidationException; -use SpinupWp\Resources\Event as EventResource; use SpinupWp\SpinupWp; class ProviderTest extends TestCase