Skip to content

Commit 5a25a5a

Browse files
committed
fix annotations for phpstan, fix endpoints on tests
1 parent 77b53da commit 5a25a5a

File tree

6 files changed

+59
-26
lines changed

6 files changed

+59
-26
lines changed

composer.lock

Lines changed: 8 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CategoryLookup.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
/**
2222
* @template InputType of array
23-
* @template OutputType of InputType|array
23+
* @template OutputType of array
2424
*
25-
* @implements TransformerInterface<InputType, OutputType>
25+
* @implements TransformerInterface<InputType>
2626
*/
2727
final readonly class CategoryLookup implements TransformerInterface
2828
{
@@ -38,7 +38,9 @@ public function __construct(
3838
}
3939

4040
/**
41-
* @return RejectionResultBucketInterface<OutputType>
41+
* @param ErrorResponse $response
42+
*
43+
* @return RejectionResultBucketInterface<string|null>
4244
*/
4345
private function rejectErrorResponse(ErrorResponse $response): RejectionResultBucketInterface
4446
{
@@ -54,7 +56,7 @@ private function rejectErrorResponse(ErrorResponse $response): RejectionResultBu
5456
}
5557

5658
/**
57-
* @return RejectionResultBucketInterface<OutputType>
59+
* @return RejectionResultBucketInterface<string|null>
5860
*/
5961
private function rejectInvalidResponse(): RejectionResultBucketInterface
6062
{
@@ -70,7 +72,7 @@ private function rejectInvalidResponse(): RejectionResultBucketInterface
7072
}
7173

7274
/**
73-
* @param InputType $line
75+
* @param array<InputType> $line
7476
*
7577
* @return OutputType
7678
*/
@@ -90,7 +92,7 @@ public function transform(): \Generator
9092
}
9193

9294
if (null === $line[$this->mappingField]) {
93-
$line = yield new AcceptanceResultBucket($this->passThrough($line));
95+
$line = yield new AcceptanceResultBucket($line);
9496
continue;
9597
}
9698

src/OrderExtractor.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
use Kiboko\Contract\Bucket\RejectionResultBucketInterface;
1010
use Kiboko\Contract\Pipeline\ExtractorInterface;
1111
use Kiboko\Magento\Client;
12+
use Kiboko\Magento\Endpoint\GetV1Orders;
1213
use Kiboko\Magento\Exception\GetV1OrdersUnauthorizedException;
1314
use Kiboko\Magento\Exception\UnexpectedStatusCodeException;
1415
use Kiboko\Magento\Model\ErrorResponse;
1516
use Kiboko\Magento\Model\SalesDataOrderInterface;
1617
use Kiboko\Magento\Model\SalesDataOrderSearchResultInterface;
1718
use Psr\Http\Client\NetworkExceptionInterface;
1819
use Psr\Log\LoggerInterface;
20+
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
1921

2022
/**
2123
* @implements ExtractorInterface<SalesDataOrderInterface>
@@ -33,14 +35,14 @@ public function __construct(
3335
/**
3436
* @param array<string,string> $parameters
3537
*
36-
* @return array<string,string>
38+
* @return array<string,mixed>
3739
*/
3840
private function applyPagination(array $parameters, int $currentPage, int $pageSize): array
3941
{
4042
return [
4143
...$parameters,
42-
'searchCriteria[currentPage]' => (string) $currentPage,
43-
'searchCriteria[pageSize]' => (string) $pageSize,
44+
'searchCriteria[currentPage]' => $currentPage,
45+
'searchCriteria[pageSize]' => $pageSize,
4446
];
4547
}
4648

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

91+
/**
92+
* @param array<string,string> $parameters
93+
*
94+
* @return RejectionResultBucketInterface<SalesDataOrderInterface>
95+
*/
96+
private function rejectUndefinedOptionsResponse(UndefinedOptionsException $response, array $parameters, int $currentPage): RejectionResultBucketInterface
97+
{
98+
$this->logger->error(
99+
$message = 'The result provided by the API client does not match the expected type. The connector compilation may have fetched incompatible versions.',
100+
[
101+
'resource' => 'getV1Orders',
102+
'method' => 'get',
103+
'queryParameters' => $parameters,
104+
'currentPage' => $currentPage,
105+
'pageSize' => $this->pageSize,
106+
],
107+
);
108+
109+
return new RejectionResultBucket($message, null);
110+
}
111+
89112
public function extract(): iterable
90113
{
91114
foreach ($this->queryParameters->walkVariants() as $parameters) {
@@ -99,6 +122,11 @@ public function extract(): iterable
99122

100123
return;
101124
}
125+
if ($response instanceof UndefinedOptionsException) {
126+
yield $this->rejectUndefinedOptionsResponse($response, $parameters, $currentPage);
127+
128+
return;
129+
}
102130
if (!$response instanceof SalesDataOrderSearchResultInterface) {
103131
yield $this->rejectInvalidResponse($parameters, $currentPage);
104132

tests/CustomerExtractorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use Kiboko\Component\PHPUnitExtension\Assert\ExtractorAssertTrait;
1212
use Kiboko\Component\PHPUnitExtension\PipelineRunner;
1313
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
14-
use Kiboko\Magento\V2_3\Client;
15-
use Kiboko\Magento\V2_3\Model\CustomerDataCustomerInterface;
16-
use Kiboko\Magento\V2_3\Model\CustomerDataCustomerSearchResultsInterface;
14+
use Kiboko\Magento\Client;
15+
use Kiboko\Magento\Model\CustomerDataCustomerInterface;
16+
use Kiboko\Magento\Model\CustomerDataCustomerSearchResultsInterface;
1717
use PHPUnit\Framework\TestCase;
1818
use Psr\Log\NullLogger;
1919

@@ -36,7 +36,7 @@ public function testIsSuccessful(): void
3636
$client = $this->createMock(Client::class);
3737
$client
3838
->expects($this->once())
39-
->method('customerCustomerRepositoryV1GetListGet')
39+
->method('getV1CustomersSearch')
4040
->willReturn(
4141
(new CustomerDataCustomerSearchResultsInterface())
4242
->setItems([

tests/OrderExtractorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
use Kiboko\Component\PHPUnitExtension\Assert\ExtractorAssertTrait;
1212
use Kiboko\Component\PHPUnitExtension\PipelineRunner;
1313
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
14-
use Kiboko\Magento\V2_3\Model\SalesDataOrderInterface;
15-
use Kiboko\Magento\V2_3\Model\SalesDataOrderSearchResultInterface;
14+
use Kiboko\Magento\Model\SalesDataOrderInterface;
15+
use Kiboko\Magento\Model\SalesDataOrderSearchResultInterface;
1616
use PHPUnit\Framework\TestCase;
1717
use Psr\Log\NullLogger;
1818

@@ -27,10 +27,10 @@ public function testIsSuccessful(): void
2727
->setCustomerId(10)
2828
->setTotalQtyOrdered(3);
2929

30-
$client = $this->createMock(\Kiboko\Magento\V2_3\Client::class);
30+
$client = $this->createMock(\Kiboko\Magento\Client::class);
3131
$client
3232
->expects($this->once())
33-
->method('salesOrderRepositoryV1GetListGet')
33+
->method('getV1Orders')
3434
->willReturn(
3535
(new SalesDataOrderSearchResultInterface)
3636
->setItems([

tests/ProductExtractorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
use Kiboko\Component\PHPUnitExtension\Assert\ExtractorAssertTrait;
1212
use Kiboko\Component\PHPUnitExtension\PipelineRunner;
1313
use Kiboko\Contract\Pipeline\PipelineRunnerInterface;
14-
use Kiboko\Magento\V2_3\Client;
15-
use Kiboko\Magento\V2_3\Model\CatalogDataProductInterface;
16-
use Kiboko\Magento\V2_3\Model\CatalogDataProductSearchResultsInterface;
14+
use Kiboko\Magento\Client;
15+
use Kiboko\Magento\Model\CatalogDataProductInterface;
16+
use Kiboko\Magento\Model\CatalogDataProductSearchResultsInterface;
1717
use PHPUnit\Framework\TestCase;
1818
use Psr\Log\NullLogger;
1919

@@ -31,7 +31,7 @@ public function testIsSuccessful(): void
3131
$client = $this->createMock(Client::class);
3232
$client
3333
->expects($this->once())
34-
->method('catalogProductRepositoryV1GetListGet')
34+
->method('getV1Products')
3535
->willReturn(
3636
(new CatalogDataProductSearchResultsInterface())
3737
->setItems([

0 commit comments

Comments
 (0)