mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-01-22 20:17:32 +00:00
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Opdavies\Glassboxx\Tests\Request;
|
|
|
|
use Opdavies\Glassboxx\Request\AuthTokenRequestInterface;
|
|
use Opdavies\Glassboxx\Request\CustomerRequest;
|
|
use Opdavies\Glassboxx\Tests\TestCase;
|
|
use Opdavies\Glassboxx\Traits\UsesCreatedAtTrait;
|
|
use Opdavies\Glassboxx\ValueObject\CustomerInterface;
|
|
use Symfony\Component\HttpClient\MockHttpClient;
|
|
use Symfony\Contracts\HttpClient\ResponseInterface;
|
|
|
|
final class CustomerRequestTest extends TestCase
|
|
{
|
|
public function testThatItCreatesACustomer(): void
|
|
{
|
|
$authTokenRequest = $this->getMockAuthTokenRequest();
|
|
|
|
$response = $this->getMockBuilder(ResponseInterface::class)
|
|
->getMock();
|
|
$response->method('getContent')->willReturn('"Success"');
|
|
|
|
$client = $this->getMockBuilder(MockHttpClient::class)->getMock();
|
|
$client->expects($this->once())
|
|
->method('request')
|
|
->with(
|
|
'POST',
|
|
CustomerRequest::ENDPOINT,
|
|
[
|
|
'auth_bearer' => $authTokenRequest->getToken(),
|
|
'headers' => [
|
|
'Content-Type' => 'application/json',
|
|
],
|
|
'body' => json_encode([
|
|
'customer' => [
|
|
'created_in' => 123,
|
|
'email' => 'oliver@oliverdavies.uk',
|
|
'firstname' => 'Oliver',
|
|
'lastname' => 'Davies',
|
|
],
|
|
]),
|
|
]
|
|
)
|
|
->willReturn($response);
|
|
|
|
$request = (new CustomerRequest($client))
|
|
->forCustomer($this->getMockCustomer())
|
|
->withAuthToken($authTokenRequest->getToken())
|
|
->withConfig($this->config);
|
|
|
|
$this->assertSame('Success', $request->execute());
|
|
}
|
|
}
|