Skip to content
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

Feature/http client test coverage #55

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4882dae
Added a mocking framework to test against the API client responses
gplanchat May 18, 2022
bd3d595
mock the token response to pass the extractor test
clemzarch May 23, 2022
29a6226
raise the minimum MSI to 30%,
clemzarch May 24, 2022
91b6351
check if Akeneo responds with code 201 during an upsert,
clemzarch May 24, 2022
60d66dc
Added Infection logging
gplanchat May 30, 2022
2760869
Upgraded the Akeneo client and removed the withEnterpriseSupport flag
gplanchat May 30, 2022
bd5edc2
raise minimum MSI to 50%,
clemzarch May 31, 2022
307f666
Merge remote-tracking branch 'origin/feature/http-client-test-coverag…
clemzarch May 31, 2022
bf90758
remove last traces of "withEnterpriseSupport" because the new client …
clemzarch May 31, 2022
92397f9
run cs-fixer and force it to avoid re-indenting PhpParser Nodes ("met…
clemzarch May 31, 2022
11490ef
remove a catch that could never be triggered,
clemzarch Jun 1, 2022
5af814d
Merge remote-tracking branch 'origin/main' into feature/http-client-t…
clemzarch Jun 2, 2022
e76e0b2
add a test for the Download capacity
clemzarch Jun 2, 2022
9dce521
rename "assetMediaFiles" to the correct endpoint "assetMediaFile",
clemzarch Jun 2, 2022
ec8d02b
add phpunit-extension to the composer.lock so it can be used in CI
clemzarch Jun 2, 2022
499cb4b
force phpstan to use php 8.1 instead of 8.0
clemzarch Jun 7, 2022
1ace4ef
remove a check in the Lookup that could never be triggered
clemzarch Jun 7, 2022
1dad2dc
test the Lookup capacity by providing the configuration as an array,
clemzarch Jun 8, 2022
3101b4d
Fixed the lookup code building
gplanchat Jun 26, 2023
303db3a
remove requirement for Enterprise Edition of client
clemzarch Aug 11, 2023
78d8dff
Merge remote-tracking branch 'origin/main' into feature/http-client-t…
clemzarch Aug 11, 2023
940910b
raise min MSI,
clemzarch Aug 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"@default": true
},
"testFramework":"phpunit",
"minMsi": 30,
"minCoveredMsi": 40
"minMsi": 50,
"minCoveredMsi": 60
}
2 changes: 0 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82,
PHPUnitLevelSetList::UP_TO_PHPUNIT_100,
Expand Down
22 changes: 19 additions & 3 deletions src/Builder/Capacity/Extractor/ListPerPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final class ListPerPage implements Builder
private null|Node\Expr|Node\Identifier $endpoint = null;
private null|Node\Expr $search = null;
private null|Node\Expr $code = null;
private null|string $type = null;

public function __construct()
{
Expand All @@ -32,13 +33,20 @@ public function withSearch(Node\Expr $search): self
return $this;
}

public function withCode(Node\Expr $code): self
public function withCode(?Node\Expr $code): self
{
$this->code = $code;

return $this;
}

public function withType(string $type): self
{
$this->type = $type;

return $this;
}

public function getNode(): Node
{
if (null === $this->endpoint) {
Expand Down Expand Up @@ -69,7 +77,7 @@ public function getNode(): Node
),
null !== $this->code ? new Node\Arg(
value: $this->code,
name: new Node\Identifier('attributeCode'),
name: $this->compileCodeNamedArgument($this->type),
) : null,
],
),
Expand All @@ -90,7 +98,7 @@ class: new Node\Name\FullyQualified(name: \Kiboko\Component\Bucket\AcceptanceRes
),
),
],
]
],
);
}

Expand All @@ -107,4 +115,12 @@ private function compileSearch(): array
),
];
}

private function compileCodeNamedArgument(string $type): Node\Identifier
{
return match ($type) {
'assetManager' => new Node\Identifier('assetFamilyCode'),
default => new Node\Identifier('attributeCode')
};
}
}
2 changes: 1 addition & 1 deletion src/Builder/Capacity/Loader/Upsert.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class: new Node\Name\FullyQualified(name: \Kiboko\Component\Bucket\AcceptanceRes
new Node\Stmt\Catch_(
types: [
new Node\Name\FullyQualified(
name: \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException::class
name: \Akeneo\Pim\ApiClient\Exception\HttpException::class,
),
],
var: new Node\Expr\Variable('exception'),
Expand Down
158 changes: 121 additions & 37 deletions src/Builder/Capacity/Lookup/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Kiboko\Plugin\Akeneo\Builder\Capacity\Lookup;

use Kiboko\Component\SatelliteToolbox\Builder\IsolatedValueAppendingBuilder;
use Kiboko\Plugin\Akeneo\MissingEndpointException;
use PhpParser\Builder;
use PhpParser\Node;
Expand Down Expand Up @@ -33,7 +34,7 @@ public function withSearch(Node\Expr $search): self
return $this;
}

public function withCode(Node\Expr $code): self
public function withCode(?Node\Expr $code): self
{
$this->code = $code;

Expand All @@ -53,47 +54,122 @@ public function getNode(): Node
throw new MissingEndpointException(message: 'Please check your capacity builder, you should have selected an endpoint.');
}

return new Node\Stmt\Expression(
new Node\Expr\Assign(
var: new Node\Expr\Variable('lookup'),
expr: new Node\Expr\MethodCall(
var: new Node\Expr\MethodCall(
var: new Node\Expr\PropertyFetch(
var: new Node\Expr\Variable('this'),
name: new Node\Identifier('client')
),
name: $this->endpoint
),
name: new Node\Identifier('all'),
args: array_filter(
[
return (new IsolatedValueAppendingBuilder(
new Node\Expr\Variable('input'),
new Node\Expr\Variable('lookup'),
array_filter([
$this->code ? new Node\Stmt\If_(
cond: new Node\Expr\FuncCall(
name: new Node\Name('is_null'),
args: [
new Node\Arg(
value: new Node\Expr\Array_(
items: $this->compileSearch(),
attributes: [
'kind' => Node\Expr\Array_::KIND_SHORT,
]
),
name: new Node\Identifier('queryParameters'),
),
null !== $this->code ? new Node\Arg(
value: $this->code,
name: $this->compileCodeNamedArgument($this->type),
) : null,
),
],
),
subNodes: [
'stmts' => [
new Node\Stmt\Return_(
expr: new Node\Expr\ConstFetch(
name: new Node\Name(name: 'null'),
),
),
],
],
) : null,
new Node\Stmt\TryCatch(
stmts: [
new Node\Stmt\Expression(
expr: new Node\Expr\Assign(
var: new Node\Expr\Variable('items'),
expr: new Node\Expr\MethodCall(
var: new Node\Expr\MethodCall(
var: new Node\Expr\PropertyFetch(
var: new Node\Expr\Variable('this'),
name: new Node\Identifier('client'),
),
name: $this->endpoint
),
name: new Node\Identifier('all'),
args: array_filter(
[
new Node\Arg(
value: new Node\Expr\Array_(
items: $this->compileSearch(),
attributes: [
'kind' => Node\Expr\Array_::KIND_SHORT,
]
),
name: new Node\Identifier('queryParameters'),
),
null !== $this->code ? new Node\Arg(
value: $this->code,
name: $this->compileCodeNamedArgument($this->type),
) : null,
],
),
),
),
),
],
catches: [
new Node\Stmt\Catch_(
types: [
new Node\Name\FullyQualified(\Akeneo\Pim\ApiClient\Exception\HttpException::class),
],
var: new Node\Expr\Variable('exception'),
stmts: [
new Node\Stmt\Expression(
expr: new Node\Expr\MethodCall(
var: new Node\Expr\PropertyFetch(
var: new Node\Expr\Variable('this'),
name: 'logger',
),
name: new Node\Identifier('error'),
args: [
new Node\Arg(
value: new Node\Expr\MethodCall(
var: new Node\Expr\Variable('exception'),
name: new Node\Identifier('getMessage'),
),
),
new Node\Arg(
value: new Node\Expr\Array_(
items: [
new Node\Expr\ArrayItem(
value: new Node\Expr\Variable('exception'),
key: new Node\Scalar\String_('exception'),
),
],
attributes: [
'kind' => Node\Expr\Array_::KIND_SHORT,
],
),
),
],
),
),
new Node\Stmt\Expression(
expr: new Node\Expr\MethodCall(
var: new Node\Expr\Variable('bucket'),
name: new Node\Identifier('reject'),
args: [
new Node\Arg(
new Node\Expr\Variable('input'),
),
],
)
),
],
),
],
),
),
);
}

private function compileCodeNamedArgument(string $type): Node\Identifier
{
return match ($type) {
'referenceEntityRecord' => new Node\Identifier('referenceEntityCode'),
'assetManager' => new Node\Identifier('assetFamilyCode'),
default => new Node\Identifier('attributeCode')
};
new Node\Stmt\Return_(
expr: new Node\Expr\Variable('items'),
),
]),
new Node\Expr\Variable('bucket')
))->getNode();
}

private function compileSearch(): array
Expand All @@ -109,4 +185,12 @@ private function compileSearch(): array
),
];
}

private function compileCodeNamedArgument(string $type): Node\Identifier
{
return match ($type) {
'assetManager' => new Node\Identifier('assetFamilyCode'),
default => new Node\Identifier('attributeCode')
};
}
}
4 changes: 2 additions & 2 deletions src/Builder/Capacity/Lookup/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function getNode(): Node
);
}

private function compileCodeNamedArgument(string $type): Node\Identifier
private function compileCodeNamedArgument(?string $type): Node\Identifier
{
return match ($type) {
'referenceEntityRecord' => new Node\Identifier('referenceEntityCode'),
Expand All @@ -153,7 +153,7 @@ private function compileCodeNamedArgument(string $type): Node\Identifier
};
}

private function compileIdentifierNamedArgument(string $type): Node\Identifier
private function compileIdentifierNamedArgument(?string $type): Node\Identifier
{
return match ($type) {
'referenceEntityRecord' => new Node\Identifier('recordCode'),
Expand Down
Loading