Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/Endpoints/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace SpinupWp\Endpoints;

class Provider extends Endpoint
{
public function metadata(string $provider): array
{
return $this->getRequest("providers/{$provider}/metadata");
}
}
6 changes: 6 additions & 0 deletions src/Resources/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ public function toArray(): array
return $this->attributes;
}

/**
* @return mixed|null
*/
public function __get(string $name)
{
return $this->attributes[$name] ?? null;
}

/**
* @param mixed $value
*/
public function __set(string $name, $value): void
{
$this->attributes[$name] = $value;
Expand Down
37 changes: 37 additions & 0 deletions tests/Endpoints/ProviderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Endpoints;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Mockery;
use PHPUnit\Framework\TestCase;
use SpinupWp\Endpoints\Provider;
use SpinupWp\SpinupWp;

class ProviderTest extends TestCase
{
public SpinupWp $spinupwp;

public Provider $endpoint;

public Client $client;

public function setUp(): void
{
$this->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);
}
}