-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Icecat connector PHPUnit tests (#26)
* removes unused service * prepares CI environment for integration tests * adds integration tests * Icecat downloader now uncompresses the downloaded file in the same directory as the compressed file
- Loading branch information
Showing
17 changed files
with
559 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
#!groovy | ||
|
||
def launchUnitTests = "yes" | ||
def launchIntegrationTests = "no" | ||
|
||
class Globals { | ||
|
@@ -12,11 +11,9 @@ class Globals { | |
stage("Checkout") { | ||
milestone 1 | ||
if (env.BRANCH_NAME =~ /^PR-/) { | ||
userInput = input(message: 'Launch tests?', parameters: [ | ||
launchIntegrationTests = input(message: 'Launch tests?', parameters: [ | ||
choice(choices: 'yes\nno', description: 'Run integration tests', name: 'launchIntegrationTests'), | ||
]) | ||
|
||
launchIntegrationTests = userInput['launchIntegrationTests'] | ||
} | ||
|
||
milestone 2 | ||
|
@@ -37,7 +34,7 @@ if (launchIntegrationTests.equals("yes")) { | |
stage("Integration tests") { | ||
def tasks = [:] | ||
|
||
tasks["phpunit-5.6-ce"] = {runIntegrationTest("5.6", "${Globals.mysqlVersion}")} | ||
tasks["phpunit-5.6-ee"] = {runIntegrationTest("5.6", "${Globals.mysqlVersion}")} | ||
|
||
parallel tasks | ||
} | ||
|
@@ -79,7 +76,7 @@ def runIntegrationTest(phpVersion, mysqlVersion) { | |
sh """ | ||
docker exec akeneo composer config repositories.icecat '{"type": "vcs", "url": "[email protected]:akeneo/icecat-connector.git", "branch": "master"}' | ||
docker exec akeneo composer require --no-update akeneo/icecat-connector:${Globals.extensionBranch} | ||
docker exec akeneo php -d memory_limit=3G /usr/local/bin/composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist | ||
docker exec akeneo php -d memory_limit=3G /usr/local/bin/composer update --optimize-autoloader --no-interaction --no-progress --prefer-dist | ||
""" | ||
|
||
dir("vendor/akeneo/icecat-connector") { | ||
|
@@ -99,10 +96,18 @@ def runIntegrationTest(phpVersion, mysqlVersion) { | |
|
||
sh """ | ||
cp vendor/akeneo/icecat-connector/src/Resources/jenkins/parameters_test.yml app/config/parameters_test.yml | ||
cat vendor/akeneo/icecat-connector/src/Resources/jenkins/routing.yml >> app/config/routing.yml | ||
cp vendor/akeneo/icecat-connector/src/Resources/jenkins/phpunit.xml app/phpunit.xml | ||
cat vendor/akeneo/icecat-connector/src/Resources/jenkins/config_test.yml >> app/config/config_test.yml | ||
""" | ||
|
||
sh "docker exec akeneo app/console pim:install --force --env=test" | ||
|
||
sh 'mkdir -p app/build/logs/' | ||
sh 'docker exec akeneo bin/phpunit -c app/phpunit.xml --log-junit app/build/logs/phpunit.xml' | ||
|
||
} finally { | ||
junit "app/build/logs/*.xml" | ||
deleteDir() | ||
} | ||
} | ||
|
62 changes: 0 additions & 62 deletions
62
src/JobParameters/FormConfigurationProvider/SimpleCsvConfiguration.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
pim_icecat_connector: | ||
settings: | ||
credentials_username: | ||
value: akeneo-test | ||
scope: app | ||
credentials_password: | ||
value: akeneo-test44 | ||
scope: app | ||
ean_attribute: | ||
value: icecat_ean | ||
scope: app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
feature_id;pim_attribute_code;ignore_flag;feature_type;feature_name;feature_description;feature_unit | ||
1006;icecat_numeric_keypad;0;y_n;Numeric keypad;Small, palm-sized, seventeen key section of a computer keyboard, usually on the very far right. The numeric keypad features digits 0 to 9, addition (+), subtraction (-), multiplication (*) and division (/) symbols, a decimal point (.) and Num Lock and Enter keys. Laptop keyboards often do not have a numpad, but may provide numpad input by holding a modifier key (typically labelled "Fn") and operating keys on the standard keyboard.; | ||
11379;icecat_processor_frequency;0;numerical;Microprocessor frequency;;MHz | ||
3233;icecat_operating_system;0;dropdown;Operating system installed;Type of operating system on a device e.g. IOS on Apple devices, Android for mobile devices.; | ||
11381;icecat_installed_ram;0;numerical;Internal memory;A computer's memory which is directly accessible to the CPU.; | ||
21719;icecat_processor_series;0;dropdown;Processor series; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
feature_id;pim_attribute_code | ||
1006;icecat_numeric_keypad | ||
11379;icecat_processor_frequency | ||
3233;icecat_operating_system | ||
11381;icecat_installed_ram | ||
21719;icecat_processor_series |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
<phpunit | ||
backupGlobals = "false" | ||
backupStaticAttributes = "false" | ||
colors = "true" | ||
convertErrorsToExceptions = "true" | ||
convertNoticesToExceptions = "true" | ||
convertWarningsToExceptions = "true" | ||
processIsolation = "false" | ||
stopOnFailure = "false" | ||
syntaxCheck = "false" | ||
bootstrap = "./autoload.php" > | ||
|
||
<testsuites> | ||
<testsuite name="Icecat_Connector_Integration_Tests"> | ||
<directory suffix="Test.php">../vendor/akeneo/icecat-connector/src/Tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
|
||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
pim_icecat_connector: | ||
resource: "@PimIcecatConnectorBundle/Resources/config/routing.yml" | ||
prefix: /icecat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<?php | ||
|
||
namespace Pim\Bundle\IcecatConnectorBundle\Tests; | ||
|
||
use Akeneo\Bundle\BatchBundle\Command\BatchCommand; | ||
use Akeneo\Bundle\BatchBundle\Command\CreateJobCommand; | ||
use Pim\Component\Catalog\AttributeTypes; | ||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\NullOutput; | ||
|
||
/** | ||
* @author Mathias METAYER <[email protected]> | ||
* @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) | ||
*/ | ||
abstract class AbstractTestCase extends KernelTestCase | ||
{ | ||
/** @var array */ | ||
private $credentials = [ | ||
'username' => null, | ||
'password' => null, | ||
]; | ||
|
||
public function setUp() | ||
{ | ||
static::bootKernel(['debug' => false]); | ||
$config = $this->get('oro_config.global'); | ||
$this->credentials['username'] = $config->get('pim_icecat_connector.credentials_username'); | ||
$this->credentials['password'] = $config->get('pim_icecat_connector.credentials_password'); | ||
$this->cleanData(); | ||
} | ||
|
||
/** | ||
* @param $serviceName | ||
* @return object | ||
*/ | ||
protected function get($serviceName) | ||
{ | ||
return static::$kernel->getContainer()->get($serviceName); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return mixed | ||
*/ | ||
protected function getParameter($name) | ||
{ | ||
return static::$kernel->getContainer()->getParameter($name); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
protected function getCredentials() | ||
{ | ||
return $this->credentials; | ||
} | ||
|
||
/** | ||
* @param array $input | ||
* @return int | ||
*/ | ||
protected function runBatchCommand(array $input = []) | ||
{ | ||
$application = new Application(static::$kernel); | ||
$batchCommand = new BatchCommand(); | ||
$batchCommand->setContainer(static::$kernel->getContainer()); | ||
$application->add($batchCommand); | ||
|
||
if (!array_key_exists('--no-log', $input)) { | ||
$input['--no-log'] = true; | ||
} | ||
|
||
$batch = $application->find('akeneo:batch:job'); | ||
return $batch->run(new ArrayInput($input), new NullOutput()); | ||
} | ||
|
||
/** | ||
* Creates an import profile | ||
* | ||
* @param string $connector | ||
* @param string $job | ||
*/ | ||
protected function createImportProfile($connector, $job) | ||
{ | ||
$application = new Application(static::$kernel); | ||
$batchCommand = new CreateJobCommand(); | ||
$batchCommand->setContainer(static::$kernel->getContainer()); | ||
$application->add($batchCommand); | ||
$cmd = $application->find('akeneo:batch:create-job'); | ||
$input = new ArrayInput([ | ||
'connector' => $connector, | ||
'job' => $job, | ||
'type' => 'import', | ||
'code' => $job, | ||
]); | ||
$cmd->run($input, new NullOutput()); | ||
} | ||
|
||
protected function loadData() | ||
{ | ||
$attributes = [ | ||
[ | ||
'code' => 'icecat_ean', | ||
'type' => AttributeTypes::TEXT, | ||
'unique' => true, | ||
], | ||
[ | ||
'code' => 'icecat_numeric_keypad', | ||
'type' => AttributeTypes::BOOLEAN, | ||
], | ||
[ | ||
'code' => 'icecat_processor_frequency', | ||
'type' => AttributeTypes::METRIC, | ||
'metric_family' => 'Frequency', | ||
'negative_allowed' => false, | ||
'decimals_allowed' => true, | ||
'default_metric_unit' => 'MEGAHERTZ', | ||
], | ||
[ | ||
'code' => 'icecat_installed_ram', | ||
'type' => AttributeTypes::METRIC, | ||
'metric_family' => 'Binary', | ||
'negative_allowed' => false, | ||
'decimals_allowed' => true, | ||
'default_metric_unit' => 'GIGABYTE', | ||
], | ||
[ | ||
'code' => 'icecat_processor_series', | ||
'type' => AttributeTypes::TEXT, | ||
], | ||
[ | ||
'code' => 'icecat_operating_system', | ||
'type' => AttributeTypes::TEXT, | ||
], | ||
]; | ||
|
||
$attributeFactory = $this->get('pim_catalog.factory.attribute'); | ||
$attributeUpdater = $this->get('pim_catalog.updater.attribute'); | ||
$attributeSaver = $this->get('pim_catalog.saver.attribute'); | ||
|
||
foreach ($attributes as $data) { | ||
$attribute = $attributeFactory->create(); | ||
$attributeUpdater->update($attribute, $data); | ||
$attributeSaver->save($attribute); | ||
} | ||
|
||
$family = $this->get('pim_catalog.factory.family')->create(); | ||
$this->get('pim_catalog.updater.family')->update($family, [ | ||
'code' => 'icecat_laptop', | ||
'attribute_as_label' => 'sku', | ||
'attributes' => [ | ||
'icecat_ean', | ||
'icecat_numeric_keypad', | ||
'icecat_installed_ram', | ||
'icecat_processor_series', | ||
'icecat_processor_frequency', | ||
'icecat_operating_system', | ||
], | ||
]); | ||
$this->get('pim_catalog.saver.family')->save($family); | ||
} | ||
|
||
/** | ||
* Removes unneeded data | ||
*/ | ||
private function cleanData() | ||
{ | ||
// remove existing job instances | ||
$em = $this->get('doctrine.orm.entity_manager'); | ||
$jobInstances = $em->getRepository($this->getParameter('akeneo_batch.entity.job_instance.class')) | ||
->findBy(['type' => 'import']); | ||
$this->get('akeneo_batch.remover.job_instance')->removeAll($jobInstances); | ||
|
||
// removes products | ||
$products = $this->get('pim_catalog.repository.product')->findAll(); | ||
$this->get('pim_catalog.remover.product')->removeAll($products); | ||
|
||
// remove non identifiers attributes | ||
$attributes = $this->get('pim_catalog.repository.attribute')->getNonIdentifierAttributes(); | ||
$this->get('pim_catalog.remover.attribute')->removeAll($attributes); | ||
|
||
// removes families | ||
$families = $this->get('pim_catalog.repository.family')->findAll(); | ||
$this->get('pim_catalog.remover.family')->removeAll($families); | ||
} | ||
} |
Oops, something went wrong.