-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix body deserialization and SetOrderState (#9)
Bug Fixes: - Fixed the post body deserialization. Billbee sends the payload as `x-www-form-urlencoded`, not a json body. - Fixed the UnitTests - Removed the `\Throwable` usage to support PHP 5.6. - Using `NewStateTypeId` instead of `NewStateId` when updating the order state. `NewStateTypeId` contains an int, `NewStateId` a string.
- Loading branch information
Showing
8 changed files
with
53 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
~ This file is part of the Billbee Custom Shop API package. | ||
~ | ||
|
@@ -8,16 +9,15 @@ | |
~ | ||
~ Created by Julian Finkler <[email protected]> | ||
--> | ||
|
||
<phpunit bootstrap="tests/autoload.php"> | ||
<testsuites> | ||
<testsuite name="UnitTests"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="tests/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</coverage> | ||
<testsuites> | ||
<testsuite name="UnitTests"> | ||
<directory suffix="Test.php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
use Exception; | ||
use MintWare\Streams\MemoryStream; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
class OrderRequestHandlerTest extends TestCase | ||
{ | ||
|
@@ -62,7 +63,7 @@ public function testGetOrders() | |
$this->assertEquals(1, $data['paging']['totalPages']); | ||
$this->assertEquals(1, $data['paging']['totalCount']); | ||
$body = '{"paging":{"page":1,"totalCount":1,"totalPages":1},"orders":[{"order_id":"1234","order_number":"456","currency_code":"EUR","delivery_source_country_code":"DE","nick_name":"GirlWhoCanFly","ship_cost":4.9,"invoice_address":{"firstname":"Kara","lastname":"Zor-El","street":"Argo Street","housenumber":"1022","address2":"Window","postcode":"90012","city":"National City","country_code":"US","company":"D.E.O.","state":"CA"},"delivery_address":{"firstname":"Kara","lastname":"Zor-El","street":"Argo Street","housenumber":"1022","address2":"Window","postcode":"90012","city":"National City","country_code":"US","company":"D.E.O.","state":"CA"},"order_date":"2019-01-01T20:00:15+0000","email":"[email protected]","phone1":"0123456789","pay_date":"2019-01-01T23:00:15+0000","ship_date":"2019-01-02T02:00:15+0000","payment_method":1,"order_status_id":2,"seller_comment":"Psst","shippingprofile_id":"super-fast","vat_id":"DE-123456","payment_transaction_id":"123444"}]}'; | ||
$this->assertEquals($body, $response->getBody()); | ||
$this->assertEquals($body, (string)$response->getBody()); | ||
} | ||
|
||
public function testGetOrdersFailsInvalidDAte() | ||
|
@@ -103,10 +104,11 @@ public function testAckOrderFailsNotFound() | |
->willThrowException(new OrderNotFoundException()); | ||
$handler = new OrderRequestHandler($repo); | ||
|
||
/** @var RequestInterface $request */ | ||
$request = new Request(); | ||
$uri = new Uri('http://localhost/?Action=AckOrder'); | ||
$req = $request->withUri($uri) | ||
->withBody(new MemoryStream(json_encode(['OrderId' => '1']))); | ||
->withBody(new MemoryStream(http_build_query(['OrderId' => '1']))); | ||
|
||
$response = $handler->handle($req, ['Action' => 'AckOrder']); | ||
|
||
|
@@ -121,10 +123,11 @@ public function testAckOrderFailsUnknownError() | |
->willThrowException(new Exception('Unknown Error')); | ||
$handler = new OrderRequestHandler($repo); | ||
|
||
/** @var RequestInterface $request */ | ||
$request = new Request(); | ||
$uri = new Uri('http://localhost/?Action=AckOrder&OrderId=1'); | ||
$req = $request->withUri($uri) | ||
->withBody(new MemoryStream(json_encode(['OrderId' => '1']))); | ||
->withBody(new MemoryStream(http_build_query(['OrderId' => '1']))); | ||
|
||
|
||
$response = $handler->handle($req, ['Action' => 'AckOrder']); | ||
|
@@ -140,10 +143,11 @@ public function testAckOrder() | |
->willReturn(null); | ||
$handler = new OrderRequestHandler($repo); | ||
|
||
/** @var RequestInterface $request */ | ||
$request = new Request(); | ||
$uri = new Uri('http://localhost/?Action=AckOrder&OrderId=1'); | ||
$req = $request->withUri($uri) | ||
->withBody(new MemoryStream(json_encode(['OrderId' => '1']))); | ||
->withBody(new MemoryStream(http_build_query(['OrderId' => '1']))); | ||
|
||
|
||
$response = $handler->handle($req, ['Action' => 'AckOrder']); | ||
|
@@ -234,19 +238,20 @@ public function testSetOrderStateFailsNoOrderId() | |
$this->assertEquals('Es wurde keine OrderId übergeben', (string)$response->getBody()); | ||
} | ||
|
||
public function testSetOrderStateFailsNoNewStateId() | ||
public function testSetOrderStateFailsNoNewStateTypeId() | ||
{ | ||
$repo = $this->createMock(OrdersRepositoryInterface::class); | ||
$handler = new OrderRequestHandler($repo); | ||
|
||
/** @var RequestInterface $request */ | ||
$request = new Request(); | ||
$uri = new Uri('http://localhost/?Action=SetOrderState'); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(json_encode(['OrderId' => '1']))); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(http_build_query(['OrderId' => '1']))); | ||
|
||
$response = $handler->handle($req, ['Action' => 'SetOrderState']); | ||
|
||
$this->assertEquals(400, $response->getStatusCode()); | ||
$this->assertEquals('Es wurde keine NewStateId übergeben', (string)$response->getBody()); | ||
$this->assertEquals('Es wurde keine NewStateTypeId übergeben', (string)$response->getBody()); | ||
} | ||
|
||
public function testSetOrderStateFailsNotFound() | ||
|
@@ -256,9 +261,10 @@ public function testSetOrderStateFailsNotFound() | |
->willThrowException(new OrderNotFoundException()); | ||
$handler = new OrderRequestHandler($repo); | ||
|
||
/** @var RequestInterface $request */ | ||
$request = new Request(); | ||
$uri = new Uri('http://localhost/?Action=SetOrderState'); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(json_encode(['OrderId' => 1, 'NewStateId' => 1]))); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(http_build_query(['OrderId' => 1, 'NewStateTypeId' => 1]))); | ||
|
||
$response = $handler->handle($req, ['Action' => 'SetOrderState']); | ||
|
||
|
@@ -273,9 +279,10 @@ public function testSetOrderStateUnknownError() | |
->willThrowException(new Exception('Unknown Error')); | ||
$handler = new OrderRequestHandler($repo); | ||
|
||
/** @var RequestInterface $request */ | ||
$request = new Request(); | ||
$uri = new Uri('http://localhost/?Action=SetOrderState'); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(json_encode(['OrderId' => 1, 'NewStateId' => 1]))); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(http_build_query(['OrderId' => 1, 'NewStateTypeId' => 1]))); | ||
|
||
$response = $handler->handle($req, ['Action' => 'SetOrderState', 'OrderId' => '1']); | ||
|
||
|
@@ -290,9 +297,10 @@ public function testSetOrderState() | |
->willReturn(true); | ||
$handler = new OrderRequestHandler($repo); | ||
|
||
/** @var RequestInterface $request */ | ||
$request = new Request(); | ||
$uri = new Uri('http://localhost/?Action=SetOrderState'); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(json_encode(['OrderId' => 1, 'NewStateId' => 1]))); | ||
$req = $request->withUri($uri)->withBody(new MemoryStream(http_build_query(['OrderId' => 1, 'NewStateTypeId' => 1]))); | ||
|
||
$response = $handler->handle($req, ['Action' => 'SetOrderState', 'OrderId' => '1']); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters