diff --git a/src/PuliPlugin.php b/src/PuliPlugin.php index 05a54bd..4b66314 100644 --- a/src/PuliPlugin.php +++ b/src/PuliPlugin.php @@ -20,6 +20,7 @@ use Composer\Script\CommandEvent; use Composer\Script\Event; use Composer\Script\ScriptEvents; +use Exception; use RuntimeException; use Webmozart\PathUtil\Path; @@ -98,49 +99,6 @@ public function __construct(PuliRunner $puliRunner = null) */ public function activate(Composer $composer, IOInterface $io) { - // Verify if Puli has the right version - try { - $versionString = $this->puliRunner->run('-V'); - } catch (PuliRunnerException $e) { - $this->printWarning($io, 'Could not determine Puli version', $e); - - return; - } - - if (!preg_match('~\d+\.\d+\.\d+(-\w+)?~', $versionString, $matches)) { - $this->printWarning($io, sprintf( - 'Could not determine Puli version. "puli -V" returned: %s', - $versionString - )); - - return; - } - - if (version_compare($matches[0], self::MIN_CLI_VERSION, '<')) { - $this->printWarning($io, sprintf( - 'Found an unsupported version of the Puli CLI: %s. Please '. - 'upgrade to version %s or higher. You can also install the '. - 'puli/cli dependency at version %s in your project.', - $matches[0], - self::MIN_CLI_VERSION, - self::MIN_CLI_VERSION - )); - - return; - } - - if (version_compare($matches[0], self::MAX_CLI_VERSION, '>')) { - $this->printWarning($io, sprintf( - 'Found an unsupported version of the Puli CLI: %s. Please '. - 'downgrade to a lower version. You can also install the '. - 'puli/cli dependency at a lower version than %s in your project.', - $matches[0], - self::MAX_CLI_VERSION - )); - - return; - } - $composer->getEventDispatcher()->addSubscriber($this); } @@ -267,16 +225,23 @@ private function initialize(Composer $composer, IOInterface $io) $this->initialized = true; // Keep the manually set runner - if ($this->puliRunner) { - return; + if (!$this->puliRunner) { + try { + // Add Composer's bin directory in case the "puli" executable is + // installed with Composer + $this->puliRunner = new PuliRunner($composer->getConfig()->get('bin-dir')); + } catch (RuntimeException $e) { + $this->printWarning($io, 'Plugin initialization failed', $e); + $this->runPostAutoloadDump = false; + $this->runPostInstall = false; + } } + // Use the runner to verify if Puli has the right version try { - // Add Composer's bin directory in case the "puli" executable is - // installed with Composer - $this->puliRunner = new PuliRunner($composer->getConfig()->get('bin-dir')); + $this->verifyPuliVersion(); } catch (RuntimeException $e) { - $io->writeError(''.$e->getMessage().''); + $this->printWarning($io, 'Version check failed', $e); $this->runPostAutoloadDump = false; $this->runPostInstall = false; } @@ -654,14 +619,23 @@ private function renamePackage($name, $newName) )); } - private function printWarning(IOInterface $io, $message, PuliRunnerException $exception = null) + /** + * @param IOInterface $io + * @param $message + * @param Exception|null $exception + */ + private function printWarning(IOInterface $io, $message, Exception $exception = null) { if (!$exception) { $reasonPhrase = ''; } elseif ($io->isVerbose()) { - $reasonPhrase = $exception->getFullError(); + $reasonPhrase = $exception instanceof PuliRunnerException + ? $exception->getFullError() + : $exception->getMessage()."\n\n".$exception->getTraceAsString(); } else { - $reasonPhrase = $exception->getShortError(); + $reasonPhrase = $exception instanceof PuliRunnerException + ? $exception->getShortError() + : $exception->getMessage(); } $io->writeError(sprintf( @@ -703,4 +677,37 @@ private function filterProdPackageNames(array $composerPackages, PackageInterfac return $result; } + + private function verifyPuliVersion() + { + $versionString = $this->puliRunner->run('-V'); + + if (!preg_match('~\d+\.\d+\.\d+(-\w+)?~', $versionString, $matches)) { + throw new RuntimeException(sprintf( + 'Could not determine Puli version. "puli -V" returned: %s', + $versionString + )); + } + + if (version_compare($matches[0], self::MIN_CLI_VERSION, '<')) { + throw new RuntimeException(sprintf( + 'Found an unsupported version of the Puli CLI: %s. Please '. + 'upgrade to version %s or higher. You can also install the '. + 'puli/cli dependency at version %s in your project.', + $matches[0], + self::MIN_CLI_VERSION, + self::MIN_CLI_VERSION + )); + } + + if (version_compare($matches[0], self::MAX_CLI_VERSION, '>')) { + throw new RuntimeException(sprintf( + 'Found an unsupported version of the Puli CLI: %s. Please '. + 'downgrade to a lower version than %s. You can also install '. + 'the puli/cli dependency in your project.', + $matches[0], + self::MAX_CLI_VERSION + )); + } + } } diff --git a/tests/PuliPluginTest.php b/tests/PuliPluginTest.php index 2ec430a..d0437ea 100644 --- a/tests/PuliPluginTest.php +++ b/tests/PuliPluginTest.php @@ -184,49 +184,6 @@ public function testActivate() $this->composer->setEventDispatcher($dispatcher); - $this->puliRunner->expects($this->at(0)) - ->method('run') - ->with('-V') - ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); - - $this->plugin->activate($this->composer, $this->io); - } - - public function testActivateDoesNothingIfVersionTooLow() - { - $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher->expects($this->never()) - ->method('addSubscriber'); - - $this->composer->setEventDispatcher($dispatcher); - - $this->puliRunner->expects($this->at(0)) - ->method('run') - ->with('-V') - ->willReturn('Puli version 1.0.0-beta8'); - - $this->plugin->activate($this->composer, $this->io); - } - - public function testActivateDoesNothingIfVersionTooHigh() - { - $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') - ->disableOriginalConstructor() - ->getMock(); - - $dispatcher->expects($this->never()) - ->method('addSubscriber'); - - $this->composer->setEventDispatcher($dispatcher); - - $this->puliRunner->expects($this->at(0)) - ->method('run') - ->with('-V') - ->willReturn('Puli version 2.0.0-alpha1'); - $this->plugin->activate($this->composer, $this->io); } @@ -264,6 +221,10 @@ public function testInstallNewPuliPackages($eventName) ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -271,21 +232,21 @@ public function testInstallNewPuliPackages($eventName) ->willReturn( "vendor/root;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1', 'package_name' => 'vendor/package1', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package2', 'package_name' => 'vendor/package2', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(3)) + $this->puliRunner->expects($this->at(4)) ->method('run') ->with('build'); @@ -328,6 +289,38 @@ public function testDoNotInstallNewPuliPackagesAfterUninstall() $this->plugin->postInstall($event); } + public function testAbortWithWarningIfVersionTooLow() + { + $event = new CommandEvent(ScriptEvents::POST_INSTALL_CMD, $this->composer, $this->io); + + $this->io->expects($this->once()) + ->method('writeError') + ->with('Warning: Version check failed: Found an unsupported version of the Puli CLI: 1.0.0-beta8. Please upgrade to version 1.0.0-beta9 or higher. You can also install the puli/cli dependency at version 1.0.0-beta9 in your project.'); + + $this->puliRunner->expects($this->once()) + ->method('run') + ->with('-V') + ->willReturn('Puli version 1.0.0-beta8'); + + $this->plugin->postInstall($event); + } + + public function testAbortWithWarningIfVersionTooHigh() + { + $event = new CommandEvent(ScriptEvents::POST_INSTALL_CMD, $this->composer, $this->io); + + $this->io->expects($this->once()) + ->method('writeError') + ->with('Warning: Version check failed: Found an unsupported version of the Puli CLI: 2.0.0-alpha1. Please downgrade to a lower version than 1.999.99999. You can also install the puli/cli dependency in your project.'); + + $this->puliRunner->expects($this->once()) + ->method('run') + ->with('-V') + ->willReturn('Puli version 2.0.0-alpha1'); + + $this->plugin->postInstall($event); + } + public function testInstallNewPuliPackagesInDifferentEnvironments() { $event = new CommandEvent(ScriptEvents::POST_INSTALL_CMD, $this->composer, $this->io); @@ -368,6 +361,10 @@ public function testInstallNewPuliPackagesInDifferentEnvironments() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -375,35 +372,35 @@ public function testInstallNewPuliPackagesInDifferentEnvironments() ->willReturn( "vendor/root;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1', 'package_name' => 'vendor/package1', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package2', 'package_name' => 'vendor/package2', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(3)) + $this->puliRunner->expects($this->at(4)) ->method('run') ->with('package --install %path% %package_name% --installer %installer% --dev', array( 'path' => $this->tempDir.'/package3', 'package_name' => 'vendor/package3', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(4)) + $this->puliRunner->expects($this->at(5)) ->method('run') ->with('package --install %path% %package_name% --installer %installer% --dev', array( 'path' => $this->tempDir.'/package4', 'package_name' => 'vendor/package4', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(5)) + $this->puliRunner->expects($this->at(6)) ->method('run') ->with('build'); @@ -426,6 +423,10 @@ public function testDoNotInstallPackagesWithoutInstallPath() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -433,7 +434,7 @@ public function testDoNotInstallPackagesWithoutInstallPath() ->willReturn( "vendor/root;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -459,6 +460,10 @@ public function testResolveAliasPackages() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -466,14 +471,14 @@ public function testResolveAliasPackages() ->willReturn( "vendor/root;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1', 'package_name' => 'vendor/package1', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -500,6 +505,10 @@ public function testInstallAliasedPackageOnlyOnce() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -507,14 +516,14 @@ public function testInstallAliasedPackageOnlyOnce() ->willReturn( "vendor/root;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1', 'package_name' => 'vendor/package1', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -530,6 +539,10 @@ public function testWarnIfInstallFails() ->with('Warning: Could not install package "vendor/package1" (at ./package1): UnsupportedVersionException: Cannot read package file /home/bernhard/Entwicklung/Web/puli/cli/puli.json at version 5.0. The highest readable version is 1.0. Please upgrade Puli.'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -538,7 +551,7 @@ public function testWarnIfInstallFails() "vendor/root;;{$this->tempDir};enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1', @@ -551,7 +564,7 @@ public function testWarnIfInstallFails() 'UnsupportedVersionException: Cannot read package file /home/bernhard/Entwicklung/Web/puli/cli/puli.json at version 5.0. The highest readable version is 1.0. Please upgrade Puli.', 'Exception trace...' )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -576,6 +589,10 @@ public function testWarnIfOverwritingPackagesInstalledByOtherInstaller() ->with('Warning: Could not install package "vendor/package1" (at ./package2): NameConflictException: A package with the name "vendor/package1" exists already.'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -584,7 +601,7 @@ public function testWarnIfOverwritingPackagesInstalledByOtherInstaller() "vendor/root;;{$this->tempDir};enabled;prod\n". "vendor/package1;spock;{$this->tempDir}/package1;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package2', @@ -597,7 +614,7 @@ public function testWarnIfOverwritingPackagesInstalledByOtherInstaller() 'NameConflictException: A package with the name "vendor/package1" exists already.', 'Exception trace...' )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -614,7 +631,11 @@ public function testWarnIfPackageLoadingFails() ->method('writeError') ->with('Warning: Could not load Puli packages: FileNotFoundException: The file foobar does not exist.'); - $this->puliRunner->expects($this->once()) + $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -638,6 +659,10 @@ public function testWarnIfPackageInstalledByComposerNotLoadable() ->with('Warning: The package "vendor/package1" (at ./package1) could not be loaded.'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -647,7 +672,7 @@ public function testWarnIfPackageInstalledByComposerNotLoadable() "vendor/package1;composer;{$this->tempDir}/package1;not-loadable;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -662,6 +687,10 @@ public function testDoNotWarnIfPackageInstalledByUserNotLoadable() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -671,7 +700,7 @@ public function testDoNotWarnIfPackageInstalledByUserNotLoadable() "vendor/package1;spock;{$this->tempDir}/package1;not-loadable;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -687,6 +716,10 @@ public function testWarnIfPackageInstalledByComposerNotFoundInDevEnvironment() ->with('Warning: The package "vendor/package1" (at ./package1) could not be found.'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -696,7 +729,7 @@ public function testWarnIfPackageInstalledByComposerNotFoundInDevEnvironment() "vendor/package1;composer;{$this->tempDir}/package1;not-found;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -711,6 +744,10 @@ public function testDoNotWarnIfPackageInstalledByComposerNotFoundInProdEnvironme ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -720,7 +757,7 @@ public function testDoNotWarnIfPackageInstalledByComposerNotFoundInProdEnvironme "vendor/package1;composer;{$this->tempDir}/package1;not-found;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -735,6 +772,10 @@ public function testDoNotWarnIfPackageInstalledByUserNotFound() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -744,7 +785,7 @@ public function testDoNotWarnIfPackageInstalledByUserNotFound() "vendor/package1;spock;{$this->tempDir}/package1;not-found;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -768,6 +809,10 @@ public function testReinstallPackagesWithInstallPathMovedToSubPath() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -777,19 +822,19 @@ public function testReinstallPackagesWithInstallPathMovedToSubPath() "vendor/package1;composer;{$this->tempDir}/package1;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --delete %package_name%', array( 'package_name' => 'vendor/package1', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1/sub/path', 'package_name' => 'vendor/package1', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(3)) + $this->puliRunner->expects($this->at(4)) ->method('run') ->with('build'); @@ -811,6 +856,10 @@ public function testReinstallPackagesWithInstallPathMovedToParentPath() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -820,19 +869,19 @@ public function testReinstallPackagesWithInstallPathMovedToParentPath() "vendor/package1;composer;{$this->tempDir}/package1/sub/path;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --delete %package_name%', array( 'package_name' => 'vendor/package1', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1', 'package_name' => 'vendor/package1', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(3)) + $this->puliRunner->expects($this->at(4)) ->method('run') ->with('build'); @@ -855,6 +904,10 @@ public function testReinstallPackagesWithChangedEnvironment() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -864,19 +917,19 @@ public function testReinstallPackagesWithChangedEnvironment() "vendor/package1;composer;{$this->tempDir}/package1;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --delete %package_name%', array( 'package_name' => 'vendor/package1', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('package --install %path% %package_name% --installer %installer% --dev', array( 'path' => $this->tempDir.'/package1', 'package_name' => 'vendor/package1', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(3)) + $this->puliRunner->expects($this->at(4)) ->method('run') ->with('build'); @@ -891,6 +944,10 @@ public function testDoNotReinstallExistingPuliPackages() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -899,14 +956,14 @@ public function testDoNotReinstallExistingPuliPackages() "vendor/root;;{$this->tempDir};enabled;prod\n". "vendor/package1;composer;{$this->tempDir}/package1;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package2', 'package_name' => 'vendor/package2', 'installer' => 'composer', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -925,6 +982,10 @@ public function testWarnIfRemoveFailsDuringReinstall() ->with('Warning: Could not remove package "vendor/package1" (at ./package1): Exception: The exception'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -934,7 +995,7 @@ public function testWarnIfRemoveFailsDuringReinstall() "vendor/package1;composer;{$this->tempDir}/package1/sub/path;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --delete %package_name%', array( 'package_name' => 'vendor/package1', @@ -945,7 +1006,7 @@ public function testWarnIfRemoveFailsDuringReinstall() 'Exception: The exception', 'Exception trace...' )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -964,6 +1025,10 @@ public function testWarnIfInstallFailsDuringReinstall() ->with('Warning: Could not install package "vendor/package1" (at ./package1): Exception: The exception'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -973,12 +1038,12 @@ public function testWarnIfInstallFailsDuringReinstall() "vendor/package1;composer;{$this->tempDir}/package1/sub/path;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --delete %package_name%', array( 'package_name' => 'vendor/package1', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('package --install %path% %package_name% --installer %installer%', array( 'path' => $this->tempDir.'/package1', @@ -991,7 +1056,7 @@ public function testWarnIfInstallFailsDuringReinstall() 'Exception: The exception', 'Exception trace...' )); - $this->puliRunner->expects($this->at(3)) + $this->puliRunner->expects($this->at(4)) ->method('run') ->with('build'); @@ -1015,6 +1080,10 @@ public function testRemoveRemovedPackagesInDevEnvironment() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -1024,12 +1093,12 @@ public function testRemoveRemovedPackagesInDevEnvironment() "vendor/package1;composer;{$this->tempDir}/package1;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;not-found;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --delete %package_name%', array( 'package_name' => 'vendor/package2', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -1049,6 +1118,10 @@ public function testDoNotRemoveRemovedPackagesInProdEnvironment() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -1058,7 +1131,7 @@ public function testDoNotRemoveRemovedPackagesInProdEnvironment() "vendor/package1;composer;{$this->tempDir}/package1;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;not-found;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -1075,6 +1148,10 @@ public function testDoNotRemovePackagesFromOtherInstaller() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -1083,7 +1160,7 @@ public function testDoNotRemovePackagesFromOtherInstaller() "vendor/root;;{$this->tempDir};enabled;prod\n". "vendor/package1;spock;{$this->tempDir}/package1;not-found;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -1111,6 +1188,10 @@ public function testWarnIfRemoveFails() ); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -1120,7 +1201,7 @@ public function testWarnIfRemoveFails() "vendor/package1;composer;{$this->tempDir}/package1;enabled;prod\n". "vendor/package2;composer;{$this->tempDir}/package2;not-found;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --delete %package_name%', array( 'package_name' => 'vendor/package2', @@ -1131,7 +1212,7 @@ public function testWarnIfRemoveFails() 'Exception: The exception', 'Exception trace...' )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -1148,6 +1229,10 @@ public function testCopyComposerPackageNameToPuli() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -1155,13 +1240,13 @@ public function testCopyComposerPackageNameToPuli() ->willReturn( "vendor/previous;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --rename %old_name% %new_name%', array( 'old_name' => 'vendor/previous', 'new_name' => 'vendor/root', )); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('build'); @@ -1178,6 +1263,10 @@ public function testDoNotCopyComposerPackageNameToPuliIfUnchanged() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -1185,7 +1274,7 @@ public function testDoNotCopyComposerPackageNameToPuliIfUnchanged() ->willReturn( "vendor/root;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('build'); @@ -1203,6 +1292,10 @@ public function testWarnIfRenameFails() ->with('Warning: Could not rename root package to "vendor/root": Exception: Some exception.'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('package --list --format %format%', array( 'format' => '%name%;%installer%;%install_path%;%state%;%env%', @@ -1210,7 +1303,7 @@ public function testWarnIfRenameFails() ->willReturn( "vendor/previous;;{$this->tempDir};enabled;prod\n" ); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('package --rename %old_name% %new_name%', array( 'old_name' => 'vendor/previous', @@ -1246,12 +1339,16 @@ public function testInsertFactoryClassIntoClassMap() ->method('writeError'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'factory.in.class', )) ->willReturn("Puli\\MyFactory\n"); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'factory.in.file', @@ -1277,7 +1374,11 @@ public function testWarnIfFactoryClassCannotBeRead() ->method('writeError') ->with('Warning: Could not load Puli configuration: Exception: Some exception.'); - $this->puliRunner->expects($this->once()) + $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'factory.in.class', @@ -1301,12 +1402,16 @@ public function testWarnIfFactoryFileCannotBeRead() ->with('Warning: Could not load Puli configuration: Exception: Some exception.'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'factory.in.class', )) ->willReturn("Puli\\MyFactory\n"); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'factory.in.file', @@ -1334,6 +1439,11 @@ public function testFailIfClassMapFileNotFound() unlink($this->tempDir.'/the-vendor/composer/autoload_classmap.php'); + $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->plugin->postAutoloadDump($event); } @@ -1349,12 +1459,16 @@ public function testInsertFactoryConstantIntoAutoload() ->with('Registering Puli\\MyFactory with the class-map autoloader'); $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(1)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'factory.in.class', )) ->willReturn("Puli\\MyFactory\n"); - $this->puliRunner->expects($this->at(1)) + $this->puliRunner->expects($this->at(2)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'factory.in.file', @@ -1384,6 +1498,11 @@ public function testFailIfAutoloadFileNotFound() unlink($this->tempDir.'/the-vendor/autoload.php'); + $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->plugin->postAutoloadDump($event); } @@ -1395,13 +1514,17 @@ public function testSetBootstrapFileToAutoloadFile() ->method('write') ->with('Setting "bootstrap-file" to "the-vendor/autoload.php"'); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'bootstrap-file', )) ->willReturn('null'); - $this->puliRunner->expects($this->at(3)) + $this->puliRunner->expects($this->at(4)) ->method('run') ->with('config %key% %value%', array( 'key' => 'bootstrap-file', @@ -1418,13 +1541,17 @@ public function testDoNotSetBootstrapFileIfAlreadySet() $this->io->expects($this->exactly(2)) ->method('write'); - $this->puliRunner->expects($this->at(2)) + $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->puliRunner->expects($this->at(3)) ->method('run') ->with('config %key% --parsed', array( 'key' => 'bootstrap-file', )) ->willReturn("my/bootstrap-file.php\n"); - $this->puliRunner->expects($this->exactly(3)) + $this->puliRunner->expects($this->exactly(4)) ->method('run'); $this->plugin->postAutoloadDump($event); @@ -1437,6 +1564,11 @@ public function testRunPostAutoloadDumpOnlyOnce() $this->io->expects($this->exactly(3)) ->method('write'); + $this->puliRunner->expects($this->at(0)) + ->method('run') + ->with('-V') + ->willReturn('Puli version '.PuliPlugin::MIN_CLI_VERSION); + $this->plugin->postAutoloadDump($event); $this->plugin->postAutoloadDump($event); } @@ -1448,6 +1580,12 @@ public function testDontRunPostAutoloadDumpAfterUninstall() $this->io->expects($this->never()) ->method('write'); + $this->io->expects($this->never()) + ->method('writeError'); + + $this->puliRunner->expects($this->never()) + ->method('run'); + $filesystem = new Filesystem(); $filesystem->remove($this->pluginClassFile);