Skip to content

Commit 606acfe

Browse files
authored
Merge pull request #69 from akeneo/API-324
API-324: Adapt client tests for being able to run both PIM versions 1.7 and master
2 parents 7e80444 + 1f6447c commit 606acfe

12 files changed

+270
-143
lines changed

Jenkinsfile

+12-4
Original file line numberDiff line numberDiff line change
@@ -306,20 +306,26 @@ void runIntegrationTest(String phpVersion, String client, String psrImplem, Stri
306306
unstash "pim_community_dev_${pimVersion}"
307307

308308
if ("master" == pimVersion) {
309+
sh "docker pull akeneo/fpm:php-7.1 || true"
310+
309311
sh "docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim --tmpfs=/var/lib/mysql/:rw,noexec,nosuid,size=400m --tmpfs=/tmp/:rw,noexec,nosuid,size=200m -d mysql:5.7"
310312
sh "docker run --name elasticsearch -e ES_JAVA_OPTS=\"-Xms256m -Xmx256m\" -d elasticsearch:5"
311313
sh "docker run --name akeneo-pim --link mysql:mysql --link elasticsearch:elasticsearch -v \$(pwd):/srv/pim -w /srv/pim -d akeneo/fpm:php-7.1"
312314
sh "docker run --name httpd --link akeneo-pim:fpm -v \$(pwd):/srv/pim -v \$(pwd)/docker/httpd.conf:/usr/local/apache2/conf/httpd.conf -v \$(pwd)/docker/akeneo.conf:/usr/local/apache2/conf/vhost.conf -w /srv/pim -d httpd:2.4"
315+
316+
// Wait for elasticsearch container ready
317+
sh "sleep 20"
318+
sh "docker exec akeneo-pim bin/console pim:install -e prod"
313319
}
314320

315321
if ("1.7" == pimVersion) {
316322
sh "docker run --name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim --tmpfs=/var/lib/mysql/:rw,noexec,nosuid,size=400m --tmpfs=/tmp/:rw,noexec,nosuid,size=200m -d mysql:5.5"
317323
sh "docker run --name akeneo-pim --link mysql:mysql -v \$(pwd):/srv/pim -v \$(pwd)/docker/akeneo.conf:/etc/apache2/sites-available/000-default.conf:ro -w /srv/pim -d akeneo/apache-php:php-5.6"
318-
}
319324

320-
// Wait for elasticsearch container ready
321-
sh "sleep 20"
322-
sh "docker exec akeneo-pim app/console pim:install -e prod"
325+
// Wait for elasticsearch container ready
326+
sh "sleep 20"
327+
sh "docker exec akeneo-pim app/console pim:install -e prod"
328+
}
323329
}
324330

325331
unstash "php-api-client_${client}_${psrImplem}_php-${phpVersion}".replaceAll("/", "_")
@@ -328,6 +334,8 @@ void runIntegrationTest(String phpVersion, String client, String psrImplem, Stri
328334
if ("master" == pimVersion) {
329335
docker.image("akeneo/php:${phpVersion}").inside("--link akeneo-pim:akeneo-pim --link httpd:httpd -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker -w /home/docker/client --privileged") {
330336
sh "sed -i \"s#baseUri: .*#baseUri: 'http://httpd'#g\" etc/parameters.yml"
337+
sh "sed -i \"s#bin_path: .*#bin_path: bin#g\" etc/parameters.yml"
338+
sh "sed -i \"s#version: .*#version: #g\" etc/parameters.yml"
331339
sh "sudo ./bin/phpunit -c phpunit.xml.dist --testsuite PHP_Client_Unit_Test_1_8 --log-junit build/logs/phpunit_integration.xml"
332340
}
333341
}

etc/parameters.yml.dist

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ pim:
88
install_path: '/srv/pim'
99
is_docker: true
1010
docker_name: akeneo-pim
11+
bin_path: app
12+
version: '1.7'

tests/Common/Api/ApiTestCase.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected function setUp()
3131
$installer = new DockerDatabaseInstaller($config['pim']['docker_name']);
3232
}
3333

34-
$installer->install($config['pim']['install_path']);
34+
$installer->install($config['pim']['install_path'], $config['pim']['bin_path']);
3535
}
3636

3737
/**
@@ -45,7 +45,7 @@ protected function createClient()
4545
$generator = new DockerCredentialGenerator($config['pim']['docker_name']);
4646
}
4747

48-
$credentials = $generator->generate($config['pim']['install_path']);
48+
$credentials = $generator->generate($config['pim']['install_path'], $config['pim']['bin_path'], $config['pim']['version']);
4949
$clientBuilder = new AkeneoPimClientBuilder($config['api']['baseUri']);
5050

5151
return $clientBuilder->buildAuthenticatedByPassword(

tests/Common/Api/Product/ListProductApiIntegration.php

-112
Original file line numberDiff line numberDiff line change
@@ -102,118 +102,6 @@ public function testAllWithSelectedAttributes()
102102
$this->assertSameContent($expectedProduct, $actualProduct);
103103
}
104104

105-
public function testAllWithSelectedLocales()
106-
{
107-
$baseUri = $this->getConfiguration()['api']['baseUri'];
108-
$api = $this->createClient()->getProductApi();
109-
$products = $api->all(10, [
110-
'locales' => 'fr_FR',
111-
'search' => [
112-
'categories' => [
113-
[
114-
'operator' => 'IN',
115-
'value' => ['sandals'],
116-
]
117-
]
118-
]
119-
]);
120-
121-
$expectedProduct = $this->sanitizeProductData([
122-
'_links' => [
123-
'self' => [
124-
'href' => $baseUri . '/api/rest/v1/products/dance_shoe',
125-
],
126-
],
127-
'identifier' => 'dance_shoe',
128-
'family' => 'sandals',
129-
'groups' => [],
130-
'variant_group' => null,
131-
'categories' => [
132-
'sandals',
133-
],
134-
'enabled' => true,
135-
'values' => [
136-
'color' => [
137-
[
138-
'locale' => null,
139-
'scope' => null,
140-
'data' => 'greem',
141-
],
142-
],
143-
'description' => [
144-
[
145-
'locale' => 'fr_FR',
146-
'scope' => 'ecommerce',
147-
'data' => 'Dansez toute la nuit !',
148-
],
149-
],
150-
'destocking_date' => [
151-
[
152-
'locale' => null,
153-
'scope' => null,
154-
'data' => '2017-06-30T00:00:00+00:00',
155-
],
156-
],
157-
'manufacturer' => [
158-
[
159-
'locale' => null,
160-
'scope' => null,
161-
'data' => 'Converse',
162-
],
163-
],
164-
'name' => [
165-
[
166-
'locale' => 'fr_FR',
167-
'scope' => null,
168-
'data' => 'Chaussure de dance',
169-
],
170-
],
171-
'side_view' => [
172-
[
173-
'locale' => null,
174-
'scope' => null,
175-
'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png',
176-
'_links' => [
177-
'download' => [
178-
'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download',
179-
],
180-
],
181-
],
182-
],
183-
'size' => [
184-
[
185-
'locale' => null,
186-
'scope' => null,
187-
'data' => '40',
188-
],
189-
],
190-
'price' => [
191-
[
192-
'locale' => null,
193-
'scope' => null,
194-
'data' => [
195-
[
196-
'amount' => '90.50',
197-
'currency' => 'USD',
198-
],
199-
[
200-
'amount' => '99.49',
201-
'currency' => 'EUR',
202-
],
203-
],
204-
],
205-
],
206-
],
207-
'created' => '2017-06-26T07:33:09+00:00',
208-
'updated' => '2017-06-26T07:33:09+00:00',
209-
'associations' => [],
210-
]);
211-
212-
$actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]);
213-
214-
$this->assertSameContent($expectedProduct, $actualProduct);
215-
}
216-
217105
public function testAllWithSelectedScope()
218106
{
219107
$baseUri = $this->getConfiguration()['api']['baseUri'];

tests/CredentialGeneratorInterface.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ interface CredentialGeneratorInterface
1414
/**
1515
* Generates credentials on the PIM.
1616
*
17-
* @param string $path path to Akeneo PIM application
17+
* @param string $path path to Akeneo PIM application
18+
* @param string $binPath path to Akeneo PIM binaries
19+
* @param string $pimVersion Akeneo PIM version
1820
*
1921
* @throws \RuntimeException if an error occured during the generation process
2022
*
2123
* @return array credentials on the form ['client_id' => 'client', 'secret' => 'secret']
2224
*/
23-
public function generate($path);
25+
public function generate($path, $binPath, $pimVersion);
2426
}

tests/DatabaseInstallerInterface.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ interface DatabaseInstallerInterface
1515
* Install the database of the PIM.
1616
*
1717
* @param string $path path to Akeneo PIM application
18+
* @param string $binPath path to Akeneo PIM binaries
1819
*
1920
* @throws \RuntimeException if an error occured during the PIM install
2021
*/
21-
public function install($path);
22+
public function install($path, $binPath);
2223
}

tests/DockerCredentialGenerator.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,15 @@ public function __construct($dockerName)
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function generate($path)
28+
public function generate($path, $binPath, $pimVersion)
2929
{
30-
$command = sprintf('docker exec %s php %s/app/console pim:oauth-server:create-client -e prod', $this->dockerName, $path);
30+
$label = "1.7" === $pimVersion ? '--label="PHP client credentials"' : '"PHP client credentials"';
31+
$command = sprintf('docker exec %s php %s/%s/console pim:oauth-server:create-client %s -e prod', $this->dockerName, $path, $binPath, $label);
3132

3233
$output = [];
3334
exec(escapeshellcmd($command), $output);
3435

35-
if (count($output) !== 3) {
36+
if (count($output) !== 4) {
3637
throw new \RuntimeException('An error occurred during the generation of the client id and secret.');
3738
}
3839

tests/DockerDatabaseInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public function __construct($dockerName)
2525
/**
2626
* {@inheritdoc}
2727
*/
28-
public function install($path)
28+
public function install($path, $binPath)
2929
{
30-
$command = sprintf('docker exec %s php %s/app/console pim:installer:db -e prod', $this->dockerName, $path);
30+
$command = sprintf('docker exec %s php %s/%s/console pim:installer:db -e prod', $this->dockerName, $path, $binPath);
3131

3232
$output = [];
3333
exec(escapeshellcmd($command), $output, $status);

tests/LocalCredentialGenerator.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@ class LocalCredentialGenerator implements CredentialGeneratorInterface
1414
/**
1515
* {@inheritdoc}
1616
*/
17-
public function generate($path)
17+
public function generate($path, $binPath, $pimVersion)
1818
{
1919
if (!is_dir($path)) {
2020
throw new \RuntimeException(sprintf('Parameter "path" is not a directory or does not exist, "%s" given.', $path));
2121
}
2222

23-
$command = sprintf('php %s/app/console pim:oauth-server:create-client -e prod', $path);
23+
$label = "1.7" === $pimVersion ? '--label="PHP client credentials"' : '"PHP client credentials"';
24+
$command = sprintf('php %s/%s/console pim:oauth-server:create-client %s -e prod', $path, $binPath, $label);
2425

2526
$output = [];
2627
exec(escapeshellcmd($command), $output);
2728

28-
if (count($output) !== 3) {
29+
if (count($output) !== 4) {
2930
throw new \RuntimeException('An error occurred during the generation of the client id and secret.');
3031
}
3132

tests/LocalDatabaseInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ class LocalDatabaseInstaller implements DatabaseInstallerInterface
1414
/**
1515
* {@inheritdoc}
1616
*/
17-
public function install($path)
17+
public function install($path, $binPath)
1818
{
1919
if (!is_dir($path)) {
2020
throw new \RuntimeException(sprintf('Parameter "path" is not a directory or does not exist, "%s" given.', $path));
2121
}
2222

23-
$command = sprintf('php %s/app/console pim:installer:db -e prod', $path);
23+
$command = sprintf('php %s/%s/console pim:installer:db -e prod', $path, $binPath);
2424

2525
$output = [];
2626
exec(escapeshellcmd($command), $output, $status);

tests/v1_7/Api/Product/ListProductApiIntegration.php

+112
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,118 @@ public function testSearchWithSeveralFiltersUsingSearchBuilder()
178178
$this->assertSameContent($expectedProduct, $actualProduct);
179179
}
180180

181+
public function testAllWithSelectedLocales()
182+
{
183+
$baseUri = $this->getConfiguration()['api']['baseUri'];
184+
$api = $this->createClient()->getProductApi();
185+
$products = $api->all(10, [
186+
'locales' => 'fr_FR',
187+
'search' => [
188+
'categories' => [
189+
[
190+
'operator' => 'IN',
191+
'value' => ['sandals'],
192+
]
193+
]
194+
]
195+
]);
196+
197+
$expectedProduct = $this->sanitizeProductData([
198+
'_links' => [
199+
'self' => [
200+
'href' => $baseUri . '/api/rest/v1/products/dance_shoe',
201+
],
202+
],
203+
'identifier' => 'dance_shoe',
204+
'family' => 'sandals',
205+
'groups' => [],
206+
'variant_group' => null,
207+
'categories' => [
208+
'sandals',
209+
],
210+
'enabled' => true,
211+
'values' => [
212+
'color' => [
213+
[
214+
'locale' => null,
215+
'scope' => null,
216+
'data' => 'greem',
217+
],
218+
],
219+
'description' => [
220+
[
221+
'locale' => 'fr_FR',
222+
'scope' => 'ecommerce',
223+
'data' => 'Dansez toute la nuit !',
224+
],
225+
],
226+
'destocking_date' => [
227+
[
228+
'locale' => null,
229+
'scope' => null,
230+
'data' => '2017-06-30T00:00:00+00:00',
231+
],
232+
],
233+
'manufacturer' => [
234+
[
235+
'locale' => null,
236+
'scope' => null,
237+
'data' => 'Converse',
238+
],
239+
],
240+
'name' => [
241+
[
242+
'locale' => 'fr_FR',
243+
'scope' => null,
244+
'data' => 'Chaussure de dance',
245+
],
246+
],
247+
'side_view' => [
248+
[
249+
'locale' => null,
250+
'scope' => null,
251+
'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png',
252+
'_links' => [
253+
'download' => [
254+
'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download',
255+
],
256+
],
257+
],
258+
],
259+
'size' => [
260+
[
261+
'locale' => null,
262+
'scope' => null,
263+
'data' => '40',
264+
],
265+
],
266+
'price' => [
267+
[
268+
'locale' => null,
269+
'scope' => null,
270+
'data' => [
271+
[
272+
'amount' => '90.50',
273+
'currency' => 'USD',
274+
],
275+
[
276+
'amount' => '99.49',
277+
'currency' => 'EUR',
278+
],
279+
],
280+
],
281+
],
282+
],
283+
'created' => '2017-06-26T07:33:09+00:00',
284+
'updated' => '2017-06-26T07:33:09+00:00',
285+
'associations' => [],
286+
]);
287+
288+
$actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]);
289+
290+
$this->assertSameContent($expectedProduct, $actualProduct);
291+
}
292+
181293
/**
182294
* @param string $identifier
183295
*

0 commit comments

Comments
 (0)