Skip to content

Commit

Permalink
MIG-4: Add a test config
Browse files Browse the repository at this point in the history
  • Loading branch information
anaelChardan committed Aug 31, 2017
1 parent 3dd0f9c commit d738b1d
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/var/*
!.gitkeep
.php_cs.cache
tests/test_config.yml
36 changes: 36 additions & 0 deletions tests/integration/ConfiguredTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace integration\Akeneo\PimMigration;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Yaml\Yaml;

/**
* Able to reach the config of a pim.
*
* @author Anael Chardan <[email protected]>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
abstract class ConfiguredTestCase extends TestCase
{
protected function getConfig(string $pimName): array
{
$configPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'test_config.yml';

$config = file_get_contents($configPath);

if (false === $config) {
throw new \Exception(sprintf('You should configure %s before running test.', $configPath));
}

$testConfiguration = Yaml::parse($config);

if (!isset($testConfiguration['parameters'][$pimName])) {
throw new \InvalidArgumentException(sprintf('The pim %s is not configured', $pimName));
}

return $testConfiguration['parameters'][$pimName];
}
}
9 changes: 6 additions & 3 deletions tests/integration/DatabaseSetupedTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @author Anael Chardan <[email protected]>
* @copyright 2017 Akeneo SAS (http://www.akeneo.com)
*/
abstract class DatabaseSetupedTestCase extends TestCase
abstract class DatabaseSetupedTestCase extends ConfiguredTestCase
{
protected $sourcePim;
protected $destinationPim;
Expand All @@ -24,8 +24,11 @@ public function setUp()
{
parent::setUp();

$this->sourcePim = new SourcePim('localhost', 3306, 'akeneo_pim_one_seven_for_test', 'akeneo_pim', 'akeneo_pim', null, null, false, null, false);
$this->destinationPim = new DestinationPim('localhost', 3306, 'akeneo_pim_two_for_test', 'akeneo_pim', 'akeneo_pim', false, null, 'akeneo_pim', 'localhost', '/a-path');
$sourcePimConfig = $this->getConfig('pim_community_standard_one_seven_with_reference_data');
$destinationPimConfig = $this->getConfig('pim_community_standard_two');

$this->sourcePim = new SourcePim($sourcePimConfig['database_host'], $sourcePimConfig['database_port'], $sourcePimConfig['database_name'], $sourcePimConfig['database_user'], $sourcePimConfig['database_password'], null, null, false, null, false, '/a-path');
$this->destinationPim = new DestinationPim($destinationPimConfig['database_host'], $destinationPimConfig['database_port'], $destinationPimConfig['database_name'], $destinationPimConfig['database_user'], $destinationPimConfig['database_password'], false, null, 'akeneo_pim', 'localhost', '/a-path');

$connection = $this->getConnection($this->destinationPim, false);
$connection->exec('DROP DATABASE IF EXISTS akeneo_pim_two_for_test');
Expand Down
15 changes: 15 additions & 0 deletions tests/test_config.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
parameters:
pim_community_standard_one_dot_seven_with_reference_data:
absolute_path: ~
database_host: ~
database_name: ~
database_port: ~
database_user: ~
database_password: ~
pim_community_standard_two_dot_zero:
absolute_path: ~
database_host: ~
database_name: ~
database_port: ~
database_user: ~
database_password: ~

0 comments on commit d738b1d

Please sign in to comment.