Skip to content

Commit d651cc6

Browse files
authored
Merge pull request #249 from akeneo/api-test-clean-up
fix(): clean api unit tests
2 parents 8619fbd + d8b13fe commit d651cc6

24 files changed

+233
-143
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"require-dev": {
3434
"friendsofphp/php-cs-fixer": "^3.5",
35-
"phpunit/phpunit": "^7.0",
35+
"phpunit/phpunit": "^8.0",
3636
"phpspec/phpspec": "^7.1",
3737
"symfony/yaml": "^4.2",
3838
"donatj/mock-webserver": "^2.0",

composer.lock

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

tests/Api/ApiTestCase.php

Lines changed: 5 additions & 9 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}
@@ -44,10 +43,7 @@ protected function tearDown(): void
4443
$this->server->stop();
4544
}
4645

47-
/**
48-
* @return AkeneoPimClientInterface
49-
*/
50-
protected function createClientByPassword()
46+
protected function createClientByPassword(): AkeneoPimClientInterface
5147
{
5248
$clientBuilder = new AkeneoPimClientBuilder($this->server->getServerRoot());
5349

@@ -59,7 +55,7 @@ protected function createClientByPassword()
5955
);
6056
}
6157

62-
protected function createClientByToken()
58+
protected function createClientByToken(): AkeneoPimClientInterface
6359
{
6460
$clientBuilder = new AkeneoPimClientBuilder($this->server->getServerRoot());
6561

@@ -71,14 +67,14 @@ protected function createClientByToken()
7167
);
7268
}
7369

74-
protected function createClientByAppToken()
70+
protected function createClientByAppToken(): AkeneoPimClientInterface
7571
{
7672
$clientBuilder = new AkeneoPimClientBuilder($this->server->getServerRoot());
7773

7874
return $clientBuilder->buildAuthenticatedByAppToken('a_token');
7975
}
8076

81-
private function getAuthenticatedJson()
77+
private function getAuthenticatedJson(): string
8278
{
8379
return <<<JSON
8480
{

tests/Api/CreateProductMediaFileTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public function test_create_media_file()
3535
$lastRequest = $this->server->getLastRequest()->jsonSerialize();
3636
Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_POST]['product'], json_encode($productInfos));
3737
Assert::assertNotEmpty($lastRequest[RequestInfo::JSON_KEY_FILES]['file']);
38-
Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_FILES]['file']['name'], 'akeneo.png');
39-
Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_FILES]['file']['type'], 'image/png');
40-
Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_FILES]['file']['size'], 8073);
38+
Assert::assertSame('akeneo.png', $lastRequest[RequestInfo::JSON_KEY_FILES]['file']['name']);
39+
Assert::assertSame('image/png', $lastRequest[RequestInfo::JSON_KEY_FILES]['file']['type']);
40+
Assert::assertSame(8073, $lastRequest[RequestInfo::JSON_KEY_FILES]['file']['size']);
4141

4242
Assert::assertSame('f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png', $response);
4343
}

tests/Api/CreateProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function test_create_invalid_product()
4343
$api->create('black_sneakers', $this->newProduct());
4444
}
4545

46-
private function newProduct()
46+
private function newProduct(): array
4747
{
4848
return [
4949
'enabled' => false,
@@ -66,7 +66,7 @@ private function newProduct()
6666
];
6767
}
6868

69-
private function expectedProduct()
69+
private function expectedProduct(): array
7070
{
7171
return [
7272
'enabled' => false,

tests/Api/DeleteProductModelTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function test_delete_product_model()
2323

2424
$response = $api->delete('docks_white');
2525

26-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'DELETE');
26+
Assert::assertSame('DELETE', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2727
Assert::assertSame(204, $response);
2828
}
2929
}

tests/Api/DeleteProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function test_create_product()
2323

2424
$response = $api->delete('docks_white');
2525

26-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'DELETE');
26+
Assert::assertSame('DELETE', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2727
Assert::assertSame(204, $response);
2828
}
2929
}

tests/Api/DownloadProductMediaFileTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function test_download_media_file()
2525
$api = $this->createClientByPassword()->getProductMediaFileApi();
2626
$mediaFile = $api->download('/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png');
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::assertInstanceOf(ResponseInterface::class, $mediaFile);
3030
Assert::assertSame(file_get_contents($expectedMediaFilePath), $mediaFile->getBody()->getContents());
3131
}

tests/Api/GetProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function test_get_product()
2323

2424
$product = $api->get('black_sneakers');
2525

26-
Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET');
26+
Assert::assertSame('GET', $this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD]);
2727
Assert::assertEquals($product, json_decode($this->getProduct(), true));
2828
}
2929

@@ -43,7 +43,7 @@ public function test_get_unknow_product()
4343
$api->get('black_sneakers');
4444
}
4545

46-
private function getProduct()
46+
private function getProduct(): string
4747
{
4848
return <<<JSON
4949
[

0 commit comments

Comments
 (0)