mirror of
https://github.com/opdavies/glassboxx-sdk-php.git
synced 2025-02-17 22:50:48 +00:00
parent
e83c6e59e4
commit
532dfd43a1
10 changed files with 342 additions and 8 deletions
|
@ -7,6 +7,7 @@ namespace Opdavies\Glassboxx\Tests\Glassboxx\Request;
|
|||
use Opdavies\Glassboxx\Request\AuthTokenRequestInterface;
|
||||
use Opdavies\Glassboxx\Request\CustomerRequest;
|
||||
use Opdavies\Glassboxx\Tests\Glassboxx\TestCase;
|
||||
use Opdavies\Glassboxx\Traits\UsesCreatedAtTrait;
|
||||
use Opdavies\Glassboxx\ValueObject\CustomerInterface;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
@ -49,15 +50,8 @@ final class CustomerRequestTest extends TestCase
|
|||
)
|
||||
->willReturn($response);
|
||||
|
||||
$customer = $this->getMockBuilder(CustomerInterface::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$customer->method('getFirstName')->willReturn('Oliver');
|
||||
$customer->method('getLastName')->willReturn('Davies');
|
||||
$customer->method('getEmailAddress')->willReturn('oliver@oliverdavies.uk');
|
||||
|
||||
$request = (new CustomerRequest($client))
|
||||
->forCustomer($customer)
|
||||
->forCustomer($this->getMockCustomer())
|
||||
->withAuthToken($authTokenRequest->getToken())
|
||||
->withConfig($this->config);
|
||||
|
||||
|
|
67
tests/Glassboxx/Request/OrderRequestTest.php
Normal file
67
tests/Glassboxx/Request/OrderRequestTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Opdavies\Glassboxx\Tests\Glassboxx\Request;
|
||||
|
||||
use DateTime;
|
||||
use Opdavies\Glassboxx\Request\OrderRequest;
|
||||
use Opdavies\Glassboxx\Tests\Glassboxx\TestCase;
|
||||
use Symfony\Component\HttpClient\MockHttpClient;
|
||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
||||
|
||||
final class OrderRequestTest extends TestCase
|
||||
{
|
||||
public function testThatItCreatesAnOrder(): void
|
||||
{
|
||||
$body = [
|
||||
'items' => [
|
||||
[
|
||||
'created_at' => '2020-06-04 12:00:00',
|
||||
'currency_code' => 'GBP',
|
||||
'customer_email' => 'oliver@oliverdavies.uk',
|
||||
'customer_firstname' => 'Oliver',
|
||||
'customer_lastname' => 'Davies',
|
||||
'discount_amount' => 0,
|
||||
'duration_for_loan' => 0,
|
||||
'hostname' => 123,
|
||||
'original_order_number' => 'abc123',
|
||||
'price_incl_tax' => 100,
|
||||
'sku' => 'this-is-the-first-sku',
|
||||
'type_of_interaction' => 'purchase',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->getMockBuilder(ResponseInterface::class)->getMock();
|
||||
$response->method('getContent')->willReturn(json_encode($body));
|
||||
|
||||
$authTokenRequest = $this->getMockAuthTokenRequest();
|
||||
|
||||
$client = $this->getMockBuilder(MockHttpClient::class)->getMock();
|
||||
$client->expects($this->once())
|
||||
->method('request')
|
||||
->with(
|
||||
'POST',
|
||||
OrderRequest::BASE_URL
|
||||
.OrderRequest::ENDPOINT,
|
||||
[
|
||||
'auth_bearer' => $authTokenRequest->getToken(),
|
||||
'headers' => [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
'body' => json_encode($body),
|
||||
]
|
||||
)
|
||||
->willReturn($response);
|
||||
|
||||
$request = (new OrderRequest($client))
|
||||
->forOrder($this->getMockOrder())
|
||||
->withAuthToken($authTokenRequest->getToken())
|
||||
->withConfig($this->config)
|
||||
->setCreatedDate('2020-06-04 12:00:00');
|
||||
|
||||
// A successful response returns the original body.
|
||||
$this->assertSame(json_encode($body), $request->execute());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue