-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
356 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Endpoints\General\Menu; | ||
|
||
use JetBrains\PhpStorm\ArrayShape; | ||
use KMA\IikoTransport\Contracts\IRequestBody; | ||
use KMA\IikoTransport\Entities\Entity; | ||
use KMA\IikoTransport\Exceptions\MissingRequiredFieldException; | ||
|
||
class OutOfStockRequest extends Entity implements IRequestBody | ||
{ | ||
/** | ||
* @required | ||
* @var string[] <uuid> Organizations for which out-of-stock lists will be requested | ||
* Can be obtained by /api/1/organizations operation | ||
*/ | ||
public array $organizationIds; | ||
|
||
const ATTRIBUTES = [ | ||
'organizationIds' => 'string[]', | ||
]; | ||
|
||
/** | ||
* @param array|null $data | ||
* @throws \KMA\IikoTransport\Exceptions\MissingRequiredFieldException | ||
*/ | ||
public function __construct( | ||
#[ArrayShape(self::ATTRIBUTES)] | ||
?array $data = null | ||
) | ||
{ | ||
if (null !== $data) { | ||
if (!isset($data['organizationIds'])) { | ||
throw new MissingRequiredFieldException('organisationId'); | ||
} | ||
|
||
$this->organizationIds = $data['organizationIds']; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Endpoints\General\Menu; | ||
|
||
use Illuminate\Support\Collection; | ||
use KMA\IikoTransport\Contracts\HasCorrelationId; | ||
use KMA\IikoTransport\Entities\Entity; | ||
use KMA\IikoTransport\Entities\StopLists\TerminalGroupStopListWrap; | ||
|
||
class OutOfStockResponse extends Entity | ||
{ | ||
use HasCorrelationId; | ||
|
||
/** | ||
* Stock list group | ||
* @required | ||
* @var \Illuminate\Support\Collection<int, \KMA\IikoTransport\Entities\StopLists\TerminalGroupStopListWrap> | ||
*/ | ||
public Collection $terminalGroupStopLists; | ||
|
||
/** | ||
* @param array|null $data | ||
*/ | ||
public function __construct(?array $data = null) | ||
{ | ||
if (null !== $data) { | ||
$this->correlationId = $data['correlationId']; | ||
|
||
$this->terminalGroupStopLists = | ||
collect($data['terminalGroupStopLists']) | ||
->map(fn (array $item): TerminalGroupStopListWrap => TerminalGroupStopListWrap::fromArray($item)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Entities\StopLists; | ||
|
||
use KMA\IikoTransport\Entities\Entity; | ||
use KMA\IikoTransport\Exceptions\MissingRequiredFieldException; | ||
|
||
class StopListItem extends Entity | ||
{ | ||
/** | ||
* @required | ||
* @var float Product balance | ||
*/ | ||
public float $balance; | ||
|
||
/** | ||
* @required | ||
* @var string <uuid> Out-of-stock list product ID | ||
*/ | ||
public string $productId; | ||
|
||
/** | ||
* @throws \KMA\IikoTransport\Exceptions\MissingRequiredFieldException | ||
*/ | ||
public function __construct(?array $data = null) | ||
{ | ||
if (null !== $data) { | ||
if (!isset($data['balance'])) { | ||
throw new MissingRequiredFieldException('balance'); | ||
} | ||
if (!isset($data['productId'])) { | ||
throw new MissingRequiredFieldException('productId'); | ||
} | ||
$this->balance = $data['balance']; | ||
$this->productId = $data['productId']; | ||
} | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Entities\StopLists; | ||
|
||
use Illuminate\Support\Collection; | ||
use KMA\IikoTransport\Entities\Entity; | ||
use KMA\IikoTransport\Exceptions\MissingRequiredFieldException; | ||
|
||
class TerminalGroupStopList extends Entity | ||
{ | ||
/** | ||
* @required | ||
* @var string <uuid> | ||
*/ | ||
public string $terminalGroupId; | ||
|
||
/** | ||
* @required | ||
* @var \Illuminate\Support\Collection<int, \KMA\IikoTransport\Entities\StopLists\StopListItem> | ||
*/ | ||
public Collection $items; | ||
|
||
/** | ||
* @throws \KMA\IikoTransport\Exceptions\MissingRequiredFieldException | ||
*/ | ||
public function __construct(?array $data = null) | ||
{ | ||
if (null !== $data) { | ||
if (!isset($data['terminalGroupId'])) { | ||
throw new MissingRequiredFieldException('terminalGroupId'); | ||
} | ||
if (!isset($data['items'])) { | ||
throw new MissingRequiredFieldException('items'); | ||
} | ||
$this->terminalGroupId = $data['terminalGroupId']; | ||
$this->items = collect($data['items']) | ||
->map(fn (array $item): StopListItem => StopListItem::fromArray($item)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Entities\StopLists; | ||
|
||
use Illuminate\Support\Collection; | ||
use KMA\IikoTransport\Entities\Entity; | ||
|
||
class TerminalGroupStopListWrap extends Entity | ||
{ | ||
/** | ||
* @required | ||
* @var string <uuid> Organization ID | ||
* Can be obtained by /api/1/organizations operation | ||
*/ | ||
public string $organizationId; | ||
|
||
/** | ||
* Items for organization | ||
* @required | ||
* @var \Illuminate\Support\Collection<int, \KMA\IikoTransport\Entities\StopLists\TerminalGroupStopList> | ||
*/ | ||
public Collection $items; | ||
|
||
public function __construct(?array $data = null) | ||
{ | ||
if (null !== $data) { | ||
$this->organizationId = $data['organizationId']; | ||
$this->items = | ||
collect($data['items']) | ||
->map(fn (array $item): TerminalGroupStopList => TerminalGroupStopList::fromArray($item)); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Tests\Entities\StopLists; | ||
|
||
use KMA\IikoTransport\Entities\StopLists\StopListItem; | ||
use KMA\IikoTransport\Tests\EntityTestCase; | ||
|
||
/** | ||
* @covers \KMA\IikoTransport\Entities\StopLists\StopListItem | ||
*/ | ||
class StopListItemTest extends EntityTestCase | ||
{ | ||
protected array $fixture = [ | ||
'name' => 'Menu/OutOfStockResponse', | ||
'path' => 'terminalGroupStopLists.items.items' | ||
]; | ||
protected string $entityClass = StopListItem::class; | ||
protected array $fields = [ | ||
'balance', | ||
'productId', | ||
]; | ||
|
||
public function testCreateEntity(): void | ||
{ | ||
$this->runCreateTests(); | ||
} | ||
|
||
protected function assertFieldValidity($entity): void | ||
{ | ||
$this->assertIsFloat($entity->balance); | ||
$this->assertIsUuid($entity->productId); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Tests\Entities\StopLists; | ||
|
||
use Illuminate\Support\Collection; | ||
use KMA\IikoTransport\Entities\StopLists\TerminalGroupStopList; | ||
use KMA\IikoTransport\Entities\StopLists\StopListItem; | ||
use KMA\IikoTransport\Tests\EntityTestCase; | ||
|
||
/** | ||
* @covers \KMA\IikoTransport\Entities\StopLists\TerminalGroupStopList | ||
*/ | ||
class TerminalGroupStopListTest extends EntityTestCase | ||
{ | ||
protected array $fixture = [ | ||
'name' => 'Menu/OutOfStockResponse', | ||
'path' => 'terminalGroupStopLists.items' | ||
]; | ||
protected string $entityClass = TerminalGroupStopList::class; | ||
protected array $fields = [ | ||
'terminalGroupId', | ||
'items', | ||
]; | ||
|
||
public function testCreateEntity(): void | ||
{ | ||
$this->runCreateTests(); | ||
} | ||
|
||
protected function assertFieldValidity($entity): void | ||
{ | ||
$this->assertIsUuid($entity->terminalGroupId); | ||
$this->assertInstanceOf(Collection::class, $entity->items); | ||
$entity->items->each(function($item) { | ||
$this->assertInstanceOf(StopListItem::class, $item); | ||
}); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
tests/Entities/StopLists/TerminalGroupStopListWrapTest.php
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace KMA\IikoTransport\Tests\Entities\StopLists; | ||
|
||
use Illuminate\Support\Collection; | ||
use KMA\IikoTransport\Entities\StopLists\TerminalGroupStopList; | ||
use KMA\IikoTransport\Entities\StopLists\TerminalGroupStopListWrap; | ||
use KMA\IikoTransport\Tests\EntityTestCase; | ||
|
||
/** | ||
* @covers \KMA\IikoTransport\Entities\StopLists\TerminalGroupStopListWrap | ||
*/ | ||
class TerminalGroupStopListWrapTest extends EntityTestCase | ||
{ | ||
protected array $fixture = [ | ||
'name' => 'Menu/OutOfStockResponse', | ||
'path' => 'terminalGroupStopLists' | ||
]; | ||
protected string $entityClass = TerminalGroupStopListWrap::class; | ||
protected array $fields = [ | ||
'organizationId', | ||
'items', | ||
]; | ||
|
||
public function testCreateEntity(): void | ||
{ | ||
$this->runCreateTests(); | ||
} | ||
|
||
protected function assertFieldValidity($entity): void | ||
{ | ||
$this->assertIsUuid($entity->organizationId); | ||
$this->assertInstanceOf(Collection::class, $entity->items); | ||
$entity->items->each(function($item) { | ||
$this->assertInstanceOf(TerminalGroupStopList::class, $item); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"organizationIds": ["7bc05553-4b68-44e8-b7bc-37be63c6d9e9"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"correlationId": "48fb4cd3-2ef6-4479-bea1-7c92721b988c", | ||
"terminalGroupStopLists": [ | ||
{ | ||
"organizationId": "7bc05553-4b68-44e8-b7bc-37be63c6d9e9", | ||
"items": [ | ||
{ | ||
"terminalGroupId": "4fab19a5-203c-4bf5-94eb-f572aa8b117b", | ||
"items": [ | ||
{ | ||
"balance": -1.0, | ||
"productId": "dcd53ddb-8104-4e48-8cc0-5df1088c6113" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
} |