-
Notifications
You must be signed in to change notification settings - Fork 13
SFCORE-3914: Implement report object from order operation response #137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5b9c0a
draft
olivierh94 26b0f9a
update order documentation
olivierh94 08570e6
correct spelling
olivierh94 8d488ac
add report
olivierh94 b272c8c
add wait method
olivierh94 5928174
minor correction
olivierh94 5f44aa2
feedback
olivierh94 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| <?php | ||
|
|
||
| namespace ShoppingFeed\Sdk\Api\Order; | ||
|
|
||
| use ShoppingFeed\Sdk\Hal\HalResource; | ||
|
|
||
|
olivierh94 marked this conversation as resolved.
|
||
| /** | ||
| * This class was designed this way to make possible to add the request associate to the batch in future version. | ||
| */ | ||
| class OrderOperationBatch | ||
| { | ||
| private OrderOperationResponse $response; | ||
|
|
||
| public function __construct(HalResource $resource) | ||
| { | ||
| $this->response = new OrderOperationResponse($resource); | ||
| } | ||
|
|
||
| public function getResponse(): OrderOperationResponse | ||
| { | ||
| return $this->response; | ||
| } | ||
| } | ||
This file contains hidden or 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,83 @@ | ||
| <?php | ||
|
|
||
| namespace ShoppingFeed\Sdk\Api\Order; | ||
|
|
||
| use ShoppingFeed\Sdk\Api\Task; | ||
| use ShoppingFeed\Sdk\Exception\RuntimeException; | ||
| use ShoppingFeed\Sdk\Hal\HalLink; | ||
| use ShoppingFeed\Sdk\Hal\HalResource; | ||
|
|
||
| class OrderOperationResponse | ||
| { | ||
| private string $batchId; | ||
|
|
||
| private Task\TicketDomain $ticketDomain; | ||
|
|
||
| /** | ||
| * @var array{int, array{ | ||
| * id: int|null, | ||
| * channelName: string|null, | ||
| * reference: string|null, | ||
| * state: string, | ||
| * message: string | ||
| * }} $report | ||
| */ | ||
| private array $report; | ||
|
|
||
| public function __construct(HalResource $resource) | ||
| { | ||
| $this->batchId = $resource->getProperty('id'); | ||
| $this->report = $resource->getProperty('report'); | ||
| $link = $resource->getLink('ticket'); | ||
|
|
||
| if (! $link instanceof HalLink) { | ||
| throw new RuntimeException('Ticket link is missing from the OrderOperationResponse resource.'); | ||
| } | ||
|
olivierh94 marked this conversation as resolved.
|
||
|
|
||
| $this->ticketDomain = new Task\TicketDomain($link); | ||
| } | ||
|
|
||
| public function getBatchId(): string | ||
| { | ||
| return $this->batchId; | ||
| } | ||
|
|
||
| /** | ||
| * Get the iterator for all tickets generated by the operation | ||
| * | ||
| * @return Task\TicketResource[] | ||
| */ | ||
| public function getTickets(): iterable | ||
| { | ||
| yield from $this->ticketDomain->getByBatch($this->batchId); | ||
| } | ||
|
|
||
| /** | ||
| * Wait for all tickets to be processed. | ||
| * | ||
| * $timeout Seconds to wait for each batch until stop | ||
| * $sleepSecs Seconds to wait between to calls | ||
| * | ||
| * @return $this The current instance | ||
| */ | ||
| public function wait(?int $timeout = null, int $sleepSecs = 1): self | ||
| { | ||
| $this->ticketDomain->getByBatch($this->batchId)->wait($timeout, $sleepSecs); | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * @return array{int, array{ | ||
| * id: int|null, | ||
| * channelName: string|null, | ||
| * reference: string|null, | ||
| * state: string, | ||
| * message: string | ||
| * }} | ||
| */ | ||
| public function getReport(): array | ||
| { | ||
| return $this->report; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,59 @@ | ||
| <?php | ||
|
|
||
| namespace ShoppingFeed\Sdk\Test\Api\Order; | ||
|
|
||
| use ShoppingFeed\Sdk\Api\Order\OrderOperationResponse; | ||
| use ShoppingFeed\Sdk\Api\Order\OrderOperationResult; | ||
| use ShoppingFeed\Sdk\Hal\HalResource; | ||
|
|
||
| class OrderOperationResponseTest extends OrderOperationTestCase | ||
| { | ||
| private HalResource $resource; | ||
| private OrderOperationResponse $response; | ||
|
|
||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
| $this->resource = $this->createResourceMock('a', 1, 'REF123', $this->link); | ||
| $this->response = new OrderOperationResponse($this->resource); | ||
| } | ||
|
|
||
| protected function getInstance(): OrderOperationResponse|OrderOperationResult | ||
| { | ||
| return $this->response; | ||
| } | ||
|
|
||
| protected function getWaitCallCount(): int | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| public function testBatchId(): void | ||
| { | ||
| $this->assertSame('a', $this->response->getBatchId()); | ||
| } | ||
|
|
||
| public function testGetReport(): void | ||
| { | ||
| $expectedReport = [ | ||
| [ | ||
| 'id' => 1, | ||
| 'channelName' => 'Channel A', | ||
| 'reference' => 'REF123', | ||
| 'state' => 'success', | ||
| 'message' => 'Order processed successfully.' | ||
| ] | ||
| ]; | ||
|
|
||
| $this->assertSame($expectedReport, $this->response->getReport()); | ||
| } | ||
|
|
||
| public function testExceptionOnMissingTicketLink(): void | ||
| { | ||
| $this->expectException(\RuntimeException::class); | ||
| $this->expectExceptionMessage('Ticket link is missing from the OrderOperationResponse resource.'); | ||
|
|
||
| $resource = $this->createResourceMock('a', 1, 'REF123'); | ||
| new OrderOperationResponse($resource); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.