Skip to content

Commit

Permalink
fix annotations for phpstan, fix endpoints on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoMessina committed Feb 2, 2024
1 parent 77b53da commit 1ebac38
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 25 deletions.
13 changes: 8 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/CategoryLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @template InputType of array
* @template OutputType of InputType|array
*
* @implements TransformerInterface<InputType, OutputType>
* @implements TransformerInterface<InputType>
*/
final readonly class CategoryLookup implements TransformerInterface
{
Expand All @@ -38,7 +38,9 @@ public function __construct(
}

/**
* @return RejectionResultBucketInterface<OutputType>
* @param ErrorResponse $response
*
* @return RejectionResultBucketInterface<string|null>
*/
private function rejectErrorResponse(ErrorResponse $response): RejectionResultBucketInterface
{
Expand All @@ -54,7 +56,7 @@ private function rejectErrorResponse(ErrorResponse $response): RejectionResultBu
}

/**
* @return RejectionResultBucketInterface<OutputType>
* @return RejectionResultBucketInterface<string|null>
*/
private function rejectInvalidResponse(): RejectionResultBucketInterface
{
Expand All @@ -70,7 +72,7 @@ private function rejectInvalidResponse(): RejectionResultBucketInterface
}

/**
* @param InputType $line
* @param array<InputType> $line
*
* @return OutputType
*/
Expand All @@ -90,7 +92,7 @@ public function transform(): \Generator
}

if (null === $line[$this->mappingField]) {
$line = yield new AcceptanceResultBucket($this->passThrough($line));
$line = yield new AcceptanceResultBucket($line);
continue;
}

Expand Down
39 changes: 36 additions & 3 deletions src/OrderExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
use Kiboko\Contract\Bucket\RejectionResultBucketInterface;
use Kiboko\Contract\Pipeline\ExtractorInterface;
use Kiboko\Magento\Client;
use Kiboko\Magento\Endpoint\GetV1Orders;
use Kiboko\Magento\Exception\GetV1OrdersUnauthorizedException;
use Kiboko\Magento\Exception\UnexpectedStatusCodeException;
use Kiboko\Magento\Model\ErrorResponse;
use Kiboko\Magento\Model\SalesDataOrderInterface;
use Kiboko\Magento\Model\SalesDataOrderSearchResultInterface;
use Psr\Http\Client\NetworkExceptionInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;

/**
* @implements ExtractorInterface<SalesDataOrderInterface>
Expand All @@ -33,14 +35,14 @@ public function __construct(
/**
* @param array<string,string> $parameters
*
* @return array<string,string>
* @return array<string,mixed>
*/
private function applyPagination(array $parameters, int $currentPage, int $pageSize): array
{
return [
...$parameters,
'searchCriteria[currentPage]' => (string) $currentPage,
'searchCriteria[pageSize]' => (string) $pageSize,
'searchCriteria[currentPage]' => $currentPage,
'searchCriteria[pageSize]' => $pageSize,
];
}

Expand Down Expand Up @@ -86,6 +88,27 @@ private function rejectInvalidResponse(array $parameters, int $currentPage): Rej
return new RejectionResultBucket($message, null);
}

/**
* @param array<string,string> $parameters
*
* @return RejectionResultBucketInterface<SalesDataOrderInterface>
*/
private function rejectUndefinedOptionsResponse(UndefinedOptionsException $response, array $parameters, int $currentPage): RejectionResultBucketInterface
{
$this->logger->error(
$message = 'The result provided by the API client does not match the expected query parameters. The connector compilation may have fetched incompatible versions.',
[
'resource' => 'getV1Orders',
'method' => 'get',
'queryParameters' => $parameters,
'currentPage' => $currentPage,
'pageSize' => $this->pageSize,
],
);

return new RejectionResultBucket($message, null);
}

public function extract(): iterable
{
foreach ($this->queryParameters->walkVariants() as $parameters) {
Expand All @@ -99,6 +122,11 @@ public function extract(): iterable

return;
}
if ($response instanceof UndefinedOptionsException) {
yield $this->rejectUndefinedOptionsResponse($response, $parameters, $currentPage);

return;
}
if (!$response instanceof SalesDataOrderSearchResultInterface) {
yield $this->rejectInvalidResponse($parameters, $currentPage);

Expand All @@ -117,6 +145,11 @@ public function extract(): iterable

return;
}
if ($response instanceof UndefinedOptionsException) {
yield $this->rejectUndefinedOptionsResponse($response, $parameters, $currentPage);

return;
}
if (!$response instanceof SalesDataOrderSearchResultInterface) {
yield $this->rejectInvalidResponse($parameters, $currentPage);

Expand Down
8 changes: 4 additions & 4 deletions tests/CustomerExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Kiboko\Component\PHPUnitExtension\Assert\ExtractorAssertTrait;
use Kiboko\Component\PHPUnitExtension\PipelineRunner;
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
use Kiboko\Magento\V2_3\Client;
use Kiboko\Magento\V2_3\Model\CustomerDataCustomerInterface;
use Kiboko\Magento\V2_3\Model\CustomerDataCustomerSearchResultsInterface;
use Kiboko\Magento\Client;
use Kiboko\Magento\Model\CustomerDataCustomerInterface;
use Kiboko\Magento\Model\CustomerDataCustomerSearchResultsInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

Expand All @@ -36,7 +36,7 @@ public function testIsSuccessful(): void
$client = $this->createMock(Client::class);
$client
->expects($this->once())
->method('customerCustomerRepositoryV1GetListGet')
->method('getV1CustomersSearch')
->willReturn(
(new CustomerDataCustomerSearchResultsInterface())
->setItems([
Expand Down
8 changes: 4 additions & 4 deletions tests/OrderExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
use Kiboko\Component\PHPUnitExtension\Assert\ExtractorAssertTrait;
use Kiboko\Component\PHPUnitExtension\PipelineRunner;
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
use Kiboko\Magento\V2_3\Model\SalesDataOrderInterface;
use Kiboko\Magento\V2_3\Model\SalesDataOrderSearchResultInterface;
use Kiboko\Magento\Model\SalesDataOrderInterface;
use Kiboko\Magento\Model\SalesDataOrderSearchResultInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

Expand All @@ -27,10 +27,10 @@ public function testIsSuccessful(): void
->setCustomerId(10)
->setTotalQtyOrdered(3);

$client = $this->createMock(\Kiboko\Magento\V2_3\Client::class);
$client = $this->createMock(\Kiboko\Magento\Client::class);
$client
->expects($this->once())
->method('salesOrderRepositoryV1GetListGet')
->method('getV1Orders')
->willReturn(
(new SalesDataOrderSearchResultInterface)
->setItems([
Expand Down
8 changes: 4 additions & 4 deletions tests/ProductExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
use Kiboko\Component\PHPUnitExtension\Assert\ExtractorAssertTrait;
use Kiboko\Component\PHPUnitExtension\PipelineRunner;
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
use Kiboko\Magento\V2_3\Client;
use Kiboko\Magento\V2_3\Model\CatalogDataProductInterface;
use Kiboko\Magento\V2_3\Model\CatalogDataProductSearchResultsInterface;
use Kiboko\Magento\Client;
use Kiboko\Magento\Model\CatalogDataProductInterface;
use Kiboko\Magento\Model\CatalogDataProductSearchResultsInterface;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;

Expand All @@ -31,7 +31,7 @@ public function testIsSuccessful(): void
$client = $this->createMock(Client::class);
$client
->expects($this->once())
->method('catalogProductRepositoryV1GetListGet')
->method('getV1Products')
->willReturn(
(new CatalogDataProductSearchResultsInterface())
->setItems([
Expand Down

0 comments on commit 1ebac38

Please sign in to comment.