forked from akeneo/transporteo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MIG-64: check the version of the destination PIM
- Loading branch information
1 parent
8fbeb53
commit 8e85faf
Showing
8 changed files
with
165 additions
and
22 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
62 changes: 62 additions & 0 deletions
62
src/Domain/MigrationStep/s050_DestinationPimInstallation/DestinationPimVersionChecker.php
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation; | ||
|
||
use Akeneo\PimMigration\Domain\Command\ChainedConsole; | ||
use Akeneo\PimMigration\Domain\Command\SymfonyCommand; | ||
use Akeneo\PimMigration\Domain\Pim\DestinationPim; | ||
|
||
/** | ||
* Checks that the version of the destination PIM is supported. | ||
* | ||
* @author Laurent Petard <[email protected]> | ||
* @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
*/ | ||
class DestinationPimVersionChecker | ||
{ | ||
const EXACT_MAJOR_VERSION = 2; | ||
const EXACT_MINOR_VERSION = 0; | ||
const MINIMUM_PATCH_VERSION = 3; | ||
|
||
/** @var ChainedConsole */ | ||
private $console; | ||
|
||
public function __construct(ChainedConsole $console) | ||
{ | ||
$this->console = $console; | ||
} | ||
|
||
/** | ||
* @throws DestinationPimCheckConfigurationException if the version of the destination PIM is not readable or is not at least 2.0.3 | ||
*/ | ||
public function check(DestinationPim $pim): void | ||
{ | ||
$systemInformation = $this->console->execute(new SymfonyCommand('pim:system:information'), $pim)->getOutput(); | ||
$version = []; | ||
|
||
if (1 !== preg_match('~Version\s+\| (?P<full>(?P<major>[0-9]+)\.(?P<minor>[0-9]+)\.(?P<patch>[0-9]+))\s+~i', $systemInformation, $version)) { | ||
throw new DestinationPimCheckConfigurationException('Failed to read the destination PIM version.'); | ||
} | ||
|
||
if ((int) $version['major'] !== self::EXACT_MAJOR_VERSION || (int) $version['minor'] !== self::EXACT_MINOR_VERSION) { | ||
throw new DestinationPimCheckConfigurationException(sprintf( | ||
'The current version of your destination PIM %s is not supported. The version should be %d.%d.x', | ||
$version['full'], | ||
self::EXACT_MAJOR_VERSION, | ||
self::EXACT_MINOR_VERSION | ||
)); | ||
} | ||
|
||
if ((int) $version['patch'] < self::MINIMUM_PATCH_VERSION) { | ||
throw new DestinationPimCheckConfigurationException(sprintf( | ||
'The current version of your destination PIM %s is not supported. The minimum version of the destination PIM is %d.%d.%d', | ||
$version['full'], | ||
self::EXACT_MAJOR_VERSION, | ||
self::EXACT_MINOR_VERSION, | ||
self::MINIMUM_PATCH_VERSION | ||
)); | ||
} | ||
} | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions
76
...Domain/MigrationStep/s050_DestinationPimInstallation/DestinationPimVersionCheckerSpec.php
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,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation; | ||
|
||
use Akeneo\PimMigration\Domain\Command\ChainedConsole; | ||
use Akeneo\PimMigration\Domain\Command\CommandResult; | ||
use Akeneo\PimMigration\Domain\Command\SymfonyCommand; | ||
use Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation\DestinationPimCheckConfigurationException; | ||
use Akeneo\PimMigration\Domain\MigrationStep\s050_DestinationPimInstallation\DestinationPimVersionChecker; | ||
use Akeneo\PimMigration\Domain\Pim\DestinationPim; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
/** | ||
* @author Laurent Petard <[email protected]> | ||
* @copyright 2017 Akeneo SAS (http://www.akeneo.com) | ||
*/ | ||
class DestinationPimVersionCheckerSpec extends ObjectBehavior | ||
{ | ||
public function let(ChainedConsole $console) | ||
{ | ||
$this->beConstructedWith($console); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(DestinationPimVersionChecker::class); | ||
} | ||
|
||
public function it_checks_an_acceptable_version(DestinationPim $pim, CommandResult $commandResult, $console) | ||
{ | ||
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult); | ||
|
||
$commandResult->getOutput()->willReturn('| Version | 2.0.3 '); | ||
|
||
$this->check($pim); | ||
} | ||
|
||
public function it_throws_an_exception_if_the_version_it_fails_to_read_the_version(DestinationPim $pim, CommandResult $commandResult, $console) | ||
{ | ||
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult); | ||
|
||
$commandResult->getOutput()->willReturn('Version : unknown'); | ||
|
||
$this->shouldThrow(new DestinationPimCheckConfigurationException('Failed to read the destination PIM version.')) | ||
->during('check', [$pim]); | ||
} | ||
|
||
public function it_throws_an_exception_if_the_version_is_not_supported(DestinationPim $pim, CommandResult $commandResult, $console) | ||
{ | ||
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult); | ||
|
||
$commandResult->getOutput()->willReturn('| Version | 2.1.0 '); | ||
|
||
$this->shouldThrow(new DestinationPimCheckConfigurationException(sprintf( | ||
'The current version of your destination PIM 2.1.0 is not supported. The version should be %d.%d.x', | ||
DestinationPimVersionChecker::EXACT_MAJOR_VERSION, | ||
DestinationPimVersionChecker::EXACT_MINOR_VERSION | ||
)))->during('check', [$pim]); | ||
} | ||
|
||
public function it_throws_an_exception_if_the_version_patch_is_below_the_minimum(DestinationPim $pim, CommandResult $commandResult, $console) | ||
{ | ||
$console->execute(new SymfonyCommand('pim:system:information'), $pim)->willReturn($commandResult); | ||
|
||
$commandResult->getOutput()->willReturn('| Version | 2.0.2 '); | ||
|
||
$this->shouldThrow(new DestinationPimCheckConfigurationException(sprintf( | ||
'The current version of your destination PIM 2.0.2 is not supported. The minimum supported version is %d.%d.%d', | ||
DestinationPimVersionChecker::EXACT_MAJOR_VERSION, | ||
DestinationPimVersionChecker::EXACT_MINOR_VERSION, | ||
DestinationPimVersionChecker::MINIMUM_PATCH_VERSION | ||
)))->during('check', [$pim]); | ||
} | ||
} |