From 4828c58f600b24c23bfde9c878ace99f7fbea65d Mon Sep 17 00:00:00 2001 From: jean-marie leroux Date: Mon, 13 Mar 2017 17:15:13 +0100 Subject: [PATCH] Jenkinsfile for automated CI (#23) --- Jenkinsfile | 106 +++++++++++++----- Tests/TextCollection/TextCollectionTest.php | 59 ++++++++++ composer.json | 4 +- .../AppBundle/Resources/config/entities.yml | 2 - .../AppEEBundle/Resources/config/entities.yml | 3 - .../config/storage_driver/orm/orm.yml | 2 - .../ExtendedCeExtension.php} | 4 +- .../ExtendedCeBundle/ExtendedCeBundle.php} | 6 +- .../ExtendedCeBundle}/Model/ProductValue.php | 2 +- .../Resources}/config/config_test.yml | 2 +- .../Resources/config/entities.yml | 2 + .../model/doctrine/ProductValue.mongodb.yml | 2 +- .../model/doctrine/ProductValue.orm.yml | 2 +- .../Resources/config/parameters_test.yml | 10 ++ .../ExtendedEeExtension.php} | 4 +- .../Doctrine/ORM/EECompletenessGenerator.php | 2 +- .../ExtendedEeBundle/ExtendedEeBundle.php} | 6 +- .../ExtendedEeBundle}/Model/ProductValue.php | 2 +- .../Model/PublishedProductValue.php | 2 +- .../Resources/config/config_test.yml | 39 +++++++ .../Resources/config/entities.yml | 3 + .../model/doctrine/ProductValue.mongodb.yml | 2 +- .../model/doctrine/ProductValue.orm.yml | 2 +- .../PublishedProductValue.mongodb.yml | 2 +- .../doctrine/PublishedProductValue.orm.yml | 2 +- .../Resources/config/parameters_test.yml | 10 ++ .../config/storage_driver/orm/orm.yml | 2 + .../TextCollectionConverterSpec.php | 1 - .../TextCollectionCompleteCheckerSpec.php | 1 - .../ProductValue/TextCollectionFilter.php | 2 +- 30 files changed, 229 insertions(+), 59 deletions(-) create mode 100644 Tests/TextCollection/TextCollectionTest.php delete mode 100644 doc/example/Acme/Bundle/AppBundle/Resources/config/entities.yml delete mode 100644 doc/example/Acme/Bundle/AppEEBundle/Resources/config/entities.yml delete mode 100644 doc/example/Acme/Bundle/AppEEBundle/Resources/config/storage_driver/orm/orm.yml rename doc/example/{Acme/Bundle/AppEEBundle/DependencyInjection/AcmeAppEEExtension.php => Pim/Bundle/ExtendedCeBundle/DependencyInjection/ExtendedCeExtension.php} (84%) rename doc/example/{Acme/Bundle/AppBundle/AcmeAppBundle.php => Pim/Bundle/ExtendedCeBundle/ExtendedCeBundle.php} (91%) rename doc/example/{Acme/Bundle/AppBundle => Pim/Bundle/ExtendedCeBundle}/Model/ProductValue.php (89%) rename doc/example/{app => Pim/Bundle/ExtendedCeBundle/Resources}/config/config_test.yml (88%) create mode 100644 doc/example/Pim/Bundle/ExtendedCeBundle/Resources/config/entities.yml rename doc/example/{Acme/Bundle/AppBundle => Pim/Bundle/ExtendedCeBundle}/Resources/config/model/doctrine/ProductValue.mongodb.yml (63%) rename doc/example/{Acme/Bundle/AppBundle => Pim/Bundle/ExtendedCeBundle}/Resources/config/model/doctrine/ProductValue.orm.yml (91%) create mode 100644 doc/example/Pim/Bundle/ExtendedCeBundle/Resources/config/parameters_test.yml rename doc/example/{Acme/Bundle/AppBundle/DependencyInjection/AcmeAppExtension.php => Pim/Bundle/ExtendedEeBundle/DependencyInjection/ExtendedEeExtension.php} (84%) rename doc/example/{Acme/Bundle/AppEEBundle => Pim/Bundle/ExtendedEeBundle}/Doctrine/ORM/EECompletenessGenerator.php (81%) rename doc/example/{Acme/Bundle/AppEEBundle/AcmeAppEEBundle.php => Pim/Bundle/ExtendedEeBundle/ExtendedEeBundle.php} (91%) rename doc/example/{Acme/Bundle/AppEEBundle => Pim/Bundle/ExtendedEeBundle}/Model/ProductValue.php (89%) rename doc/example/{Acme/Bundle/AppEEBundle => Pim/Bundle/ExtendedEeBundle}/Model/PublishedProductValue.php (90%) create mode 100644 doc/example/Pim/Bundle/ExtendedEeBundle/Resources/config/config_test.yml create mode 100644 doc/example/Pim/Bundle/ExtendedEeBundle/Resources/config/entities.yml rename doc/example/{Acme/Bundle/AppEEBundle => Pim/Bundle/ExtendedEeBundle}/Resources/config/model/doctrine/ProductValue.mongodb.yml (63%) rename doc/example/{Acme/Bundle/AppEEBundle => Pim/Bundle/ExtendedEeBundle}/Resources/config/model/doctrine/ProductValue.orm.yml (91%) rename doc/example/{Acme/Bundle/AppEEBundle => Pim/Bundle/ExtendedEeBundle}/Resources/config/model/doctrine/PublishedProductValue.mongodb.yml (59%) rename doc/example/{Acme/Bundle/AppEEBundle => Pim/Bundle/ExtendedEeBundle}/Resources/config/model/doctrine/PublishedProductValue.orm.yml (90%) create mode 100644 doc/example/Pim/Bundle/ExtendedEeBundle/Resources/config/parameters_test.yml create mode 100644 doc/example/Pim/Bundle/ExtendedEeBundle/Resources/config/storage_driver/orm/orm.yml diff --git a/Jenkinsfile b/Jenkinsfile index aed8448..cfae6cb 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -49,10 +49,8 @@ if (launchUnitTests.equals("yes")) { def tasks = [:] tasks["phpspec-5.6"] = {runPhpSpecTest("5.6")} - tasks["phpspec-7.0"] = {runPhpSpecTest("7.0")} tasks["phpspec-7.1"] = {runPhpSpecTest("7.1")} - - tasks["php-cs-fixer-7.1"] = {runPhpCsFixerTest("7.0")} + tasks["php-cs-fixer-5.6"] = {runPhpCsFixerTest("5.6")} parallel tasks } @@ -62,7 +60,8 @@ if (launchIntegrationTests.equals("yes")) { stage("Integration tests") { def tasks = [:] - tasks["phpunit-5.6-ce"] = {runIntegrationTest("5.6")} + tasks["phpunit-5.6-ce"] = {runIntegrationTestCe("5.6")} + tasks["phpunit-5.6-ee"] = {runIntegrationTestEe("5.6")} parallel tasks } @@ -114,35 +113,88 @@ def runPhpCsFixerTest(version) { } } -def runIntegrationTest(version) { +def runIntegrationTestCe(version) { node('docker') { deleteDir() - docker.image("mysql:5.5").withRun("--name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim") { - docker.image("carcel/php:${version}").inside("--link mysql:mysql -v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") { - unstash "pim_community" - - if (version != "5.6") { - sh "composer require --no-update alcaeus/mongo-php-adapter" + try { + docker.image("mysql:5.5").withRun("--name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim") { + docker.image("carcel/php:${version}").inside("--link mysql:mysql -v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") { + unstash "pim_community" + + if (version != "5.6") { + sh "composer require --no-update alcaeus/mongo-php-adapter" + } + + sh "composer require --no-update phpunit/phpunit:5.4 akeneo/extended-attribute-type:${Globals.extensionBranch}" + sh "composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist" + dir("vendor/akeneo/extended-attribute-type") { + deleteDir() + unstash "extended_attributes" + } + sh 'ln -s $(pwd)/vendor/akeneo/extended-attribute-type/doc/example/Pim src/Pim' + sh 'composer dump-autoload -o' + + sh "cp vendor/akeneo/extended-attribute-type/doc/example/Pim/Bundle/ExtendedCeBundle/Resources/config/config_test.yml app/config/config_test.yml" + sh "cp vendor/akeneo/extended-attribute-type/doc/example/Pim/Bundle/ExtendedCeBundle/Resources/config/parameters_test.yml app/config/parameters_test.yml" + + sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExtendedCeBundle\\\\ExtendedCeBundle(),#' app/AppKernel.php" + sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExtendedAttributeTypeBundle\\\\PimExtendedAttributeTypeBundle(),#' app/AppKernel.php" + sh "cat app/AppKernel.php" + + + sh "rm ./app/cache/* -rf" + sh "./app/console --env=test pim:install --force" + sh "mkdir -p app/build/logs/" + sh "./bin/phpunit -c app/ --log-junit app/build/logs/phpunit.xml vendor/akeneo/extended-attribute-type/Tests" } + } + } finally { + sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${version}] /\" app/build/logs/*.xml" + junit "app/build/logs/*.xml" + deleteDir() + } + } +} - sh "composer require --no-update phpunit/phpunit akeneo/extended-attribute-type ${Globals.extensionBranch}" - sh "composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist" - - dir("vendor/akeneo/extended_attributes") { - unstash "extended_attributes" +def runIntegrationTestEe(version) { + node('docker') { + deleteDir() + try { + docker.image("mysql:5.5").withRun("--name mysql -e MYSQL_ROOT_PASSWORD=root -e MYSQL_USER=akeneo_pim -e MYSQL_PASSWORD=akeneo_pim -e MYSQL_DATABASE=akeneo_pim") { + docker.image("carcel/php:${version}").inside("--link mysql:mysql -v /home/akeneo/.composer:/home/akeneo/.composer -e COMPOSER_HOME=/home/akeneo/.composer") { + unstash "pim_enterprise" + + if (version != "5.6") { + sh "composer require --no-update alcaeus/mongo-php-adapter" + } + + sh "composer require --no-update phpunit/phpunit:5.4 akeneo/extended-attribute-type:${Globals.extensionBranch}" + sh "composer update --ignore-platform-reqs --optimize-autoloader --no-interaction --no-progress --prefer-dist" + dir("vendor/akeneo/extended-attribute-type") { + deleteDir() + unstash "extended_attributes" + } + sh 'ln -s $(pwd)/vendor/akeneo/extended-attribute-type/doc/example/Pim src/Pim' + sh 'composer dump-autoload -o' + + sh "cp vendor/akeneo/extended-attribute-type/doc/example/Pim/Bundle/ExtendedEeBundle/Resources/config/config_test.yml app/config/config_test.yml" + sh "cp vendor/akeneo/extended-attribute-type/doc/example/Pim/Bundle/ExtendedEeBundle/Resources/config/parameters_test.yml app/config/parameters_test.yml" + + sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExtendedEeBundle\\\\ExtendedEeBundle(),#' app/AppKernel.php" + sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExtendedAttributeTypeBundle\\\\PimExtendedAttributeTypeBundle(),#' app/AppKernel.php" + sh "cat app/AppKernel.php" + + + sh "rm ./app/cache/* -rf" + sh "./app/console --env=test pim:install --force" + sh "mkdir -p app/build/logs/" + sh "./bin/phpunit -c app/ --log-junit app/build/logs/phpunit.xml vendor/akeneo/extended-attribute-type/Tests" } - sh "composer dump-autoload -o" - - sh "cp app/config/parameters.yml.dist app/config/parameters_test.yml" - sh "sed -i 's/database_host: localhost/database_host: mysql/' app/config/parameters_test.yml" - sh "echo '' >> app/config/parameters_test.yml" - sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Pim\\\\Bundle\\\\ExtendedAttributeTypeBundle\\\\PimExtendedAttributeTypeBundle(),#' app/AppKernel.php" - sh "sed -i 's#// your app bundles should be registered here#\\0\\nnew Acme\\\\Bundle\\\\AppBundle\\\\AcmeAppBundle(),#' app/AppKernel.php" - - sh "cp vendor/akeneo/extended_attributes/doc/example/app/config/config_test.yml app/config/config_test.yml" - - sh "./app/console --env=test pim:install --force" } + } finally { + sh "sed -i \"s/testcase name=\\\"/testcase name=\\\"[php-${version}] /\" app/build/logs/*.xml" + junit "app/build/logs/*.xml" + deleteDir() } } } diff --git a/Tests/TextCollection/TextCollectionTest.php b/Tests/TextCollection/TextCollectionTest.php new file mode 100644 index 0000000..15acfc7 --- /dev/null +++ b/Tests/TextCollection/TextCollectionTest.php @@ -0,0 +1,59 @@ +container = self::$kernel->getContainer(); + $connection = $this->container->get('doctrine.dbal.default_connection'); + $purger = new DBALPurger($connection, ['pim_catalog_group_attribute', 'pim_catalog_attribute']); + $purger->purge(); + + $this->attributeRepo = $this->container->get('pim_catalog.repository.attribute'); + $this->attributeGroupRepo = $this->container->get('pim_catalog.repository.attribute_group'); + } + + public function testCreateAttribute() + { + $factory = $this->container->get('pim_catalog.factory.attribute'); + $attribute = $factory->createAttribute('pim_catalog_text_collection'); + $attribute->setCode('my_collection'); + $this->assertEquals(ExtendedAttributeTypes::TEXT_COLLECTION, $attribute->getAttributeType()); + $this->assertEquals(ExtendedAttributeTypes::BACKEND_TYPE_TEXT_COLLECTION, $attribute->getBackendType()); + + $defaultGroup = $this->attributeGroupRepo->findDefaultAttributeGroup(); + $attribute->setGroup($defaultGroup); + + $saver = $this->container->get('pim_catalog.saver.attribute'); + $saver->save($attribute); + unset($attributeGroupRepo); + unset($attribute); + + /** @var AttributeInterface $savedAttribute */ + $savedAttribute = $this->attributeRepo->findOneByIdentifier('my_collection'); + $this->assertInstanceOf(AttributeInterface::class, $savedAttribute); + $this->assertEquals(ExtendedAttributeTypes::TEXT_COLLECTION, $savedAttribute->getAttributeType()); + $this->assertEquals(ExtendedAttributeTypes::BACKEND_TYPE_TEXT_COLLECTION, $savedAttribute->getBackendType()); + $this->assertEquals($defaultGroup->getCode(), $savedAttribute->getGroup()->getCode()); + } +} diff --git a/composer.json b/composer.json index 0603795..eb0004a 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,9 @@ }, "autoload": { "psr-4": { - "Pim\\Bundle\\ExtendedAttributeTypeBundle\\": "src/" + "Pim\\Bundle\\ExtendedAttributeTypeBundle\\": "src/", + "Pim\\Bundle\\ExtendedCeBundle\\": "doc/example/PimBundle/ExtendedCeBundle", + "Pim\\Bundle\\ExtendedEeBundle\\": "doc/example/PimBundle/ExtendedEeBundle" } }, "config": { diff --git a/doc/example/Acme/Bundle/AppBundle/Resources/config/entities.yml b/doc/example/Acme/Bundle/AppBundle/Resources/config/entities.yml deleted file mode 100644 index 8695c25..0000000 --- a/doc/example/Acme/Bundle/AppBundle/Resources/config/entities.yml +++ /dev/null @@ -1,2 +0,0 @@ -parameters: - pim_catalog.entity.product_value.class: Acme\Bundle\AppBundle\Model\ProductValue diff --git a/doc/example/Acme/Bundle/AppEEBundle/Resources/config/entities.yml b/doc/example/Acme/Bundle/AppEEBundle/Resources/config/entities.yml deleted file mode 100644 index 043344a..0000000 --- a/doc/example/Acme/Bundle/AppEEBundle/Resources/config/entities.yml +++ /dev/null @@ -1,3 +0,0 @@ -parameters: - pim_catalog.entity.product_value.class: Acme\Bundle\AppEEBundle\Model\ProductValue - pimee_workflow.entity.published_product_value.class: Acme\Bundle\AppEEBundle\Model\PublishedProductValue diff --git a/doc/example/Acme/Bundle/AppEEBundle/Resources/config/storage_driver/orm/orm.yml b/doc/example/Acme/Bundle/AppEEBundle/Resources/config/storage_driver/orm/orm.yml deleted file mode 100644 index 9819d17..0000000 --- a/doc/example/Acme/Bundle/AppEEBundle/Resources/config/storage_driver/orm/orm.yml +++ /dev/null @@ -1,2 +0,0 @@ -parameters: - pim_catalog.doctrine.completeness_generator.class: Acme\Bundle\AppEEBundle\Doctrine\ORM\EECompletenessGenerator diff --git a/doc/example/Acme/Bundle/AppEEBundle/DependencyInjection/AcmeAppEEExtension.php b/doc/example/Pim/Bundle/ExtendedCeBundle/DependencyInjection/ExtendedCeExtension.php similarity index 84% rename from doc/example/Acme/Bundle/AppEEBundle/DependencyInjection/AcmeAppEEExtension.php rename to doc/example/Pim/Bundle/ExtendedCeBundle/DependencyInjection/ExtendedCeExtension.php index 928a590..a9a5c80 100644 --- a/doc/example/Acme/Bundle/AppEEBundle/DependencyInjection/AcmeAppEEExtension.php +++ b/doc/example/Pim/Bundle/ExtendedCeBundle/DependencyInjection/ExtendedCeExtension.php @@ -1,6 +1,6 @@ */ -class AcmeAppEEExtension extends Extension +class ExtendedCeExtension extends Extension { /** * {@inheritdoc} diff --git a/doc/example/Acme/Bundle/AppBundle/AcmeAppBundle.php b/doc/example/Pim/Bundle/ExtendedCeBundle/ExtendedCeBundle.php similarity index 91% rename from doc/example/Acme/Bundle/AppBundle/AcmeAppBundle.php rename to doc/example/Pim/Bundle/ExtendedCeBundle/ExtendedCeBundle.php index 120c155..8f657cc 100644 --- a/doc/example/Acme/Bundle/AppBundle/AcmeAppBundle.php +++ b/doc/example/Pim/Bundle/ExtendedCeBundle/ExtendedCeBundle.php @@ -1,6 +1,6 @@ */ -class AcmeAppBundle extends Bundle +class ExtendedCeBundle extends Bundle { /** * {@inheritdoc} @@ -18,7 +18,7 @@ class AcmeAppBundle extends Bundle public function build(ContainerBuilder $container) { $productMappings = [ - realpath(__DIR__ . '/Resources/config/model/doctrine') => 'Acme\Bundle\AppBundle\Model' + realpath(__DIR__ . '/Resources/config/model/doctrine') => 'Pim\Bundle\ExtendedCeBundle\Model' ]; $container->addCompilerPass( diff --git a/doc/example/Acme/Bundle/AppBundle/Model/ProductValue.php b/doc/example/Pim/Bundle/ExtendedCeBundle/Model/ProductValue.php similarity index 89% rename from doc/example/Acme/Bundle/AppBundle/Model/ProductValue.php rename to doc/example/Pim/Bundle/ExtendedCeBundle/Model/ProductValue.php index a24139e..d2cda78 100644 --- a/doc/example/Acme/Bundle/AppBundle/Model/ProductValue.php +++ b/doc/example/Pim/Bundle/ExtendedCeBundle/Model/ProductValue.php @@ -1,6 +1,6 @@ */ -class AcmeAppExtension extends Extension +class ExtendedEeExtension extends Extension { /** * {@inheritdoc} diff --git a/doc/example/Acme/Bundle/AppEEBundle/Doctrine/ORM/EECompletenessGenerator.php b/doc/example/Pim/Bundle/ExtendedEeBundle/Doctrine/ORM/EECompletenessGenerator.php similarity index 81% rename from doc/example/Acme/Bundle/AppEEBundle/Doctrine/ORM/EECompletenessGenerator.php rename to doc/example/Pim/Bundle/ExtendedEeBundle/Doctrine/ORM/EECompletenessGenerator.php index 8527a6c..4af1c74 100644 --- a/doc/example/Acme/Bundle/AppEEBundle/Doctrine/ORM/EECompletenessGenerator.php +++ b/doc/example/Pim/Bundle/ExtendedEeBundle/Doctrine/ORM/EECompletenessGenerator.php @@ -1,6 +1,6 @@ */ -class AcmeAppEEBundle extends Bundle +class ExtendedEeBundle extends Bundle { /** * {@inheritdoc} @@ -18,7 +18,7 @@ class AcmeAppEEBundle extends Bundle public function build(ContainerBuilder $container) { $productMappings = [ - realpath(__DIR__ . '/Resources/config/model/doctrine') => 'Acme\Bundle\AppEEBundle\Model' + realpath(__DIR__ . '/Resources/config/model/doctrine') => 'Pim\Bundle\ExtendedEeBundle\Model' ]; $container->addCompilerPass( diff --git a/doc/example/Acme/Bundle/AppEEBundle/Model/ProductValue.php b/doc/example/Pim/Bundle/ExtendedEeBundle/Model/ProductValue.php similarity index 89% rename from doc/example/Acme/Bundle/AppEEBundle/Model/ProductValue.php rename to doc/example/Pim/Bundle/ExtendedEeBundle/Model/ProductValue.php index e947ef0..2d02412 100644 --- a/doc/example/Acme/Bundle/AppEEBundle/Model/ProductValue.php +++ b/doc/example/Pim/Bundle/ExtendedEeBundle/Model/ProductValue.php @@ -1,6 +1,6 @@