Skip to content

Commit

Permalink
Merge pull request #69 from akeneo/API-324
Browse files Browse the repository at this point in the history
API-324: Adapt client tests for being able to run both PIM versions 1.7 and master
  • Loading branch information
momoss authored Aug 24, 2017
2 parents 7e80444 + 1f6447c commit 606acfe
Show file tree
Hide file tree
Showing 12 changed files with 270 additions and 143 deletions.
16 changes: 12 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,26 @@ void runIntegrationTest(String phpVersion, String client, String psrImplem, Stri
unstash "pim_community_dev_${pimVersion}"

if ("master" == pimVersion) {
sh "docker pull akeneo/fpm:php-7.1 || true"

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"
sh "docker run --name elasticsearch -e ES_JAVA_OPTS=\"-Xms256m -Xmx256m\" -d elasticsearch:5"
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"
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"

// Wait for elasticsearch container ready
sh "sleep 20"
sh "docker exec akeneo-pim bin/console pim:install -e prod"
}

if ("1.7" == pimVersion) {
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"
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"
}

// Wait for elasticsearch container ready
sh "sleep 20"
sh "docker exec akeneo-pim app/console pim:install -e prod"
// Wait for elasticsearch container ready
sh "sleep 20"
sh "docker exec akeneo-pim app/console pim:install -e prod"
}
}

unstash "php-api-client_${client}_${psrImplem}_php-${phpVersion}".replaceAll("/", "_")
Expand All @@ -328,6 +334,8 @@ void runIntegrationTest(String phpVersion, String client, String psrImplem, Stri
if ("master" == pimVersion) {
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") {
sh "sed -i \"s#baseUri: .*#baseUri: 'http://httpd'#g\" etc/parameters.yml"
sh "sed -i \"s#bin_path: .*#bin_path: bin#g\" etc/parameters.yml"
sh "sed -i \"s#version: .*#version: #g\" etc/parameters.yml"
sh "sudo ./bin/phpunit -c phpunit.xml.dist --testsuite PHP_Client_Unit_Test_1_8 --log-junit build/logs/phpunit_integration.xml"
}
}
Expand Down
2 changes: 2 additions & 0 deletions etc/parameters.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pim:
install_path: '/srv/pim'
is_docker: true
docker_name: akeneo-pim
bin_path: app
version: '1.7'
4 changes: 2 additions & 2 deletions tests/Common/Api/ApiTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected function setUp()
$installer = new DockerDatabaseInstaller($config['pim']['docker_name']);
}

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

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

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

return $clientBuilder->buildAuthenticatedByPassword(
Expand Down
112 changes: 0 additions & 112 deletions tests/Common/Api/Product/ListProductApiIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,118 +102,6 @@ public function testAllWithSelectedAttributes()
$this->assertSameContent($expectedProduct, $actualProduct);
}

public function testAllWithSelectedLocales()
{
$baseUri = $this->getConfiguration()['api']['baseUri'];
$api = $this->createClient()->getProductApi();
$products = $api->all(10, [
'locales' => 'fr_FR',
'search' => [
'categories' => [
[
'operator' => 'IN',
'value' => ['sandals'],
]
]
]
]);

$expectedProduct = $this->sanitizeProductData([
'_links' => [
'self' => [
'href' => $baseUri . '/api/rest/v1/products/dance_shoe',
],
],
'identifier' => 'dance_shoe',
'family' => 'sandals',
'groups' => [],
'variant_group' => null,
'categories' => [
'sandals',
],
'enabled' => true,
'values' => [
'color' => [
[
'locale' => null,
'scope' => null,
'data' => 'greem',
],
],
'description' => [
[
'locale' => 'fr_FR',
'scope' => 'ecommerce',
'data' => 'Dansez toute la nuit !',
],
],
'destocking_date' => [
[
'locale' => null,
'scope' => null,
'data' => '2017-06-30T00:00:00+00:00',
],
],
'manufacturer' => [
[
'locale' => null,
'scope' => null,
'data' => 'Converse',
],
],
'name' => [
[
'locale' => 'fr_FR',
'scope' => null,
'data' => 'Chaussure de dance',
],
],
'side_view' => [
[
'locale' => null,
'scope' => null,
'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png',
'_links' => [
'download' => [
'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download',
],
],
],
],
'size' => [
[
'locale' => null,
'scope' => null,
'data' => '40',
],
],
'price' => [
[
'locale' => null,
'scope' => null,
'data' => [
[
'amount' => '90.50',
'currency' => 'USD',
],
[
'amount' => '99.49',
'currency' => 'EUR',
],
],
],
],
],
'created' => '2017-06-26T07:33:09+00:00',
'updated' => '2017-06-26T07:33:09+00:00',
'associations' => [],
]);

$actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]);

$this->assertSameContent($expectedProduct, $actualProduct);
}

public function testAllWithSelectedScope()
{
$baseUri = $this->getConfiguration()['api']['baseUri'];
Expand Down
6 changes: 4 additions & 2 deletions tests/CredentialGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ interface CredentialGeneratorInterface
/**
* Generates credentials on the PIM.
*
* @param string $path path to Akeneo PIM application
* @param string $path path to Akeneo PIM application
* @param string $binPath path to Akeneo PIM binaries
* @param string $pimVersion Akeneo PIM version
*
* @throws \RuntimeException if an error occured during the generation process
*
* @return array credentials on the form ['client_id' => 'client', 'secret' => 'secret']
*/
public function generate($path);
public function generate($path, $binPath, $pimVersion);
}
3 changes: 2 additions & 1 deletion tests/DatabaseInstallerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ interface DatabaseInstallerInterface
* Install the database of the PIM.
*
* @param string $path path to Akeneo PIM application
* @param string $binPath path to Akeneo PIM binaries
*
* @throws \RuntimeException if an error occured during the PIM install
*/
public function install($path);
public function install($path, $binPath);
}
7 changes: 4 additions & 3 deletions tests/DockerCredentialGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ public function __construct($dockerName)
/**
* {@inheritdoc}
*/
public function generate($path)
public function generate($path, $binPath, $pimVersion)
{
$command = sprintf('docker exec %s php %s/app/console pim:oauth-server:create-client -e prod', $this->dockerName, $path);
$label = "1.7" === $pimVersion ? '--label="PHP client credentials"' : '"PHP client credentials"';
$command = sprintf('docker exec %s php %s/%s/console pim:oauth-server:create-client %s -e prod', $this->dockerName, $path, $binPath, $label);

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

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

Expand Down
4 changes: 2 additions & 2 deletions tests/DockerDatabaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function __construct($dockerName)
/**
* {@inheritdoc}
*/
public function install($path)
public function install($path, $binPath)
{
$command = sprintf('docker exec %s php %s/app/console pim:installer:db -e prod', $this->dockerName, $path);
$command = sprintf('docker exec %s php %s/%s/console pim:installer:db -e prod', $this->dockerName, $path, $binPath);

$output = [];
exec(escapeshellcmd($command), $output, $status);
Expand Down
7 changes: 4 additions & 3 deletions tests/LocalCredentialGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ class LocalCredentialGenerator implements CredentialGeneratorInterface
/**
* {@inheritdoc}
*/
public function generate($path)
public function generate($path, $binPath, $pimVersion)
{
if (!is_dir($path)) {
throw new \RuntimeException(sprintf('Parameter "path" is not a directory or does not exist, "%s" given.', $path));
}

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions tests/LocalDatabaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class LocalDatabaseInstaller implements DatabaseInstallerInterface
/**
* {@inheritdoc}
*/
public function install($path)
public function install($path, $binPath)
{
if (!is_dir($path)) {
throw new \RuntimeException(sprintf('Parameter "path" is not a directory or does not exist, "%s" given.', $path));
}

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

$output = [];
exec(escapeshellcmd($command), $output, $status);
Expand Down
112 changes: 112 additions & 0 deletions tests/v1_7/Api/Product/ListProductApiIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,118 @@ public function testSearchWithSeveralFiltersUsingSearchBuilder()
$this->assertSameContent($expectedProduct, $actualProduct);
}

public function testAllWithSelectedLocales()
{
$baseUri = $this->getConfiguration()['api']['baseUri'];
$api = $this->createClient()->getProductApi();
$products = $api->all(10, [
'locales' => 'fr_FR',
'search' => [
'categories' => [
[
'operator' => 'IN',
'value' => ['sandals'],
]
]
]
]);

$expectedProduct = $this->sanitizeProductData([
'_links' => [
'self' => [
'href' => $baseUri . '/api/rest/v1/products/dance_shoe',
],
],
'identifier' => 'dance_shoe',
'family' => 'sandals',
'groups' => [],
'variant_group' => null,
'categories' => [
'sandals',
],
'enabled' => true,
'values' => [
'color' => [
[
'locale' => null,
'scope' => null,
'data' => 'greem',
],
],
'description' => [
[
'locale' => 'fr_FR',
'scope' => 'ecommerce',
'data' => 'Dansez toute la nuit !',
],
],
'destocking_date' => [
[
'locale' => null,
'scope' => null,
'data' => '2017-06-30T00:00:00+00:00',
],
],
'manufacturer' => [
[
'locale' => null,
'scope' => null,
'data' => 'Converse',
],
],
'name' => [
[
'locale' => 'fr_FR',
'scope' => null,
'data' => 'Chaussure de dance',
],
],
'side_view' => [
[
'locale' => null,
'scope' => null,
'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png',
'_links' => [
'download' => [
'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download',
],
],
],
],
'size' => [
[
'locale' => null,
'scope' => null,
'data' => '40',
],
],
'price' => [
[
'locale' => null,
'scope' => null,
'data' => [
[
'amount' => '90.50',
'currency' => 'USD',
],
[
'amount' => '99.49',
'currency' => 'EUR',
],
],
],
],
],
'created' => '2017-06-26T07:33:09+00:00',
'updated' => '2017-06-26T07:33:09+00:00',
'associations' => [],
]);

$actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]);

$this->assertSameContent($expectedProduct, $actualProduct);
}

/**
* @param string $identifier
*
Expand Down
Loading

0 comments on commit 606acfe

Please sign in to comment.