Skip to content

Commit 56a4e85

Browse files
author
Samuel Gomis
committed
fix(): clean api unit tests
1 parent 8619fbd commit 56a4e85

34 files changed

+133
-143
lines changed

tests/Api/ApiTestCase.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
*/
1818
abstract class ApiTestCase extends TestCase
1919
{
20-
/** @var MockWebServer */
21-
protected $server;
20+
protected MockWebServer $server;
2221

2322
/**
2423
* {@inheritdoc}
@@ -47,7 +46,7 @@ protected function tearDown(): void
4746
/**
4847
* @return AkeneoPimClientInterface
4948
*/
50-
protected function createClientByPassword()
49+
protected function createClientByPassword(): AkeneoPimClientInterface
5150
{
5251
$clientBuilder = new AkeneoPimClientBuilder($this->server->getServerRoot());
5352

@@ -59,7 +58,7 @@ protected function createClientByPassword()
5958
);
6059
}
6160

62-
protected function createClientByToken()
61+
protected function createClientByToken(): AkeneoPimClientInterface
6362
{
6463
$clientBuilder = new AkeneoPimClientBuilder($this->server->getServerRoot());
6564

@@ -71,14 +70,14 @@ protected function createClientByToken()
7170
);
7271
}
7372

74-
protected function createClientByAppToken()
73+
protected function createClientByAppToken(): AkeneoPimClientInterface
7574
{
7675
$clientBuilder = new AkeneoPimClientBuilder($this->server->getServerRoot());
7776

7877
return $clientBuilder->buildAuthenticatedByAppToken('a_token');
7978
}
8079

81-
private function getAuthenticatedJson()
80+
private function getAuthenticatedJson(): string
8281
{
8382
return <<<JSON
8483
{

tests/Api/Asset/GetAssetIntegration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function test_get_asset()
2525
$api = $this->createClientByPassword()->getAssetManagerApi();
2626
$asset = $api->get('packshot', 'battleship');
2727

28-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
28+
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2929
Assert::assertEquals($asset, json_decode($this->getAsset(), true));
3030
}
3131

tests/Api/AssetAttribute/GetAssetFamilyAttributeIntegration.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ public function test_get_asset_family_attribute()
2525
$api = $this->createClientByPassword()->getAssetAttributeApi();
2626
$familyAttribute = $api->get('packshot', 'media_preview');
2727

28-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
28+
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2929
Assert::assertEquals($familyAttribute, json_decode($this->getPackshotPreviewAttribute(), true));
3030
}
3131

32-
/**
33-
* @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException
34-
* @expectedExceptionMessage Resource `foo` does not exist.
35-
*/
3632
public function test_get_unknown_asset_family_attribute()
3733
{
34+
$this->expectExceptionMessage("Resource `foo` does not exist.");
35+
$this->expectException(\Akeneo\Pim\ApiClient\Exception\NotFoundHttpException::class);
3836
$this->server->setResponseOfPath(
3937
'/'. sprintf(AssetAttributeApi::ASSET_ATTRIBUTE_URI, 'packshot', 'foo'),
4038
new ResponseStack(

tests/Api/AssetAttribute/ListAllAssetFamilyAttributesIntegration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function test_list_family_attributes()
2525
$api = $this->createClientByPassword()->getAssetAttributeApi();
2626
$assetFamilyAttributes = $api->all('packshot');
2727

28-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
28+
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2929
Assert::assertEquals($assetFamilyAttributes, json_decode($this->getAssetFamilyAttributes(), true));
3030
}
3131

tests/Api/AssetAttributeOption/GetAssetFamilyAttributeOptionIntegration.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ public function test_get_asset_family_attribute_option()
2525
$api = $this->createClientByPassword()->getAssetAttributeOptionApi();
2626
$familyAttributeOption = $api->get('packshot', 'wearing_model_size', 'small');
2727

28-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
28+
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2929
Assert::assertEquals($familyAttributeOption, json_decode($this->getPackshotAttributeOption(), true));
3030
}
3131

32-
/**
33-
* @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException
34-
* @expectedExceptionMessage Resource `XLS` does not exist.
35-
*/
3632
public function test_get_unknown_asset_family_attribute_option()
3733
{
34+
$this->expectExceptionMessage("Resource `XLS` does not exist.");
35+
$this->expectException(\Akeneo\Pim\ApiClient\Exception\NotFoundHttpException::class);
3836
$this->server->setResponseOfPath(
3937
'/'. sprintf(AssetAttributeOptionApi::ASSET_ATTRIBUTE_OPTION_URI, 'packshot', 'wearing_model_size', 'XLS'),
4038
new ResponseStack(

tests/Api/AssetAttributeOption/ListAllAssetFamilyAttributeOptionsIntegration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function test_list_family_attribute_options()
2929
$api = $this->createClientByPassword()->getAssetAttributeOptionApi();
3030
$assetFamilyAttributeOptions = $api->all('packshot', 'wearing_model_size');
3131

32-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
32+
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
3333
Assert::assertEquals($assetFamilyAttributeOptions, json_decode($this->getAssetFamilyAttributeOptions(), true));
3434
}
3535

tests/Api/AssetFamily/GetAssetFamilyIntegration.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ public function test_get_asset_family()
2525
$api = $this->createClientByPassword()->getAssetFamilyApi();
2626
$product = $api->get('packshot');
2727

28-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
28+
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2929
Assert::assertEquals($product, json_decode($this->getPackshot(), true));
3030
}
3131

32-
/**
33-
* @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException
34-
* @expectedExceptionMessage Asset family "foo" does not exist.
35-
*/
3632
public function test_get_unknown_asset_family()
3733
{
34+
$this->expectExceptionMessage("Asset family \"foo\" does not exist.");
35+
$this->expectException(\Akeneo\Pim\ApiClient\Exception\NotFoundHttpException::class);
3836
$this->server->setResponseOfPath(
3937
'/'. sprintf(AssetFamilyApi::ASSET_FAMILY_URI, 'foo'),
4038
new ResponseStack(

tests/Api/AssetFamily/ListAllAssetFamiliesIntegration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ListAllAssetFamiliesIntegration extends ApiTestCase
1515
public function test_list_per_page()
1616
{
1717
$this->server->setResponseOfPath(
18-
'/' . sprintf(AssetFamilyApi::ASSET_FAMILIES_URI),
18+
'/' . AssetFamilyApi::ASSET_FAMILIES_URI,
1919
new ResponseStack(
2020
new Response($this->getFirstPage(), [], 200),
2121
new Response($this->getSecondPage(), [], 200)

tests/Api/AssetMediaFile/CreateAssetMediaFileIntegration.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ public function test_create_asset_media_file()
2424

2525
Assert::assertNotEmpty($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']);
2626
Assert::assertSame(
27-
$this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['name'],
28-
'unicorn.png'
27+
'unicorn.png',
28+
$this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['name']
2929
);
3030
Assert::assertSame(
31-
$this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['type'],
32-
'image/png'
31+
'image/png',
32+
$this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['type']
3333
);
3434
Assert::assertSame(
35-
$this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['size'],
36-
11255
35+
11255,
36+
$this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_FILES]['file']['size']
3737
);
3838
Assert::assertSame('my-asset-media-code', $response);
3939
}

0 commit comments

Comments
 (0)