diff --git a/composer.json b/composer.json index d215adc..ec9a64e 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "require-dev": { "composer/composer": "~1.0", "jakub-onderka/php-parallel-lint": "~0.8", - "mikey179/vfsStream": "~1.2", + "mikey179/vfsstream": "~1.2", "phpunit/phpunit": "~5.6", "squizlabs/php_codesniffer": "~2.0" }, @@ -32,11 +32,14 @@ "psr-4": {"DrupalComposer\\Composer\\Tests\\": "tests"} }, "scripts": { + "test:unit": "phpunit --log-junit=reports/unitreport.xml --coverage-text --coverage-html=reports/coverage --coverage-clover=reports/coverage.xml", + "phpcs": "phpcs --encoding=utf-8 --standard=PSR2 --report-checkstyle=reports/checkstyle-phpcs.xml --report-full --extensions=php src/* tests/*", + "phpcbf": "phpcbf --standard=PSR2 --extensions=php src/* tests/*", "test": [ "composer validate --no-interaction", "parallel-lint src tests", - "phpunit --log-junit=reports/unitreport.xml --coverage-text --coverage-html=reports/coverage --coverage-clover=reports/coverage.xml", - "phpcs --encoding=utf-8 --standard=PSR2 --report-checkstyle=reports/checkstyle-phpcs.xml --report-full --extensions=php src/* tests/*" + "@test:unit", + "@phpcs" ] } } diff --git a/src/DrupalInfo.php b/src/DrupalInfo.php index 0783395..729b4f4 100644 --- a/src/DrupalInfo.php +++ b/src/DrupalInfo.php @@ -147,8 +147,13 @@ protected function doWriteInfoFiles(PackageInterface $package) */ protected function doRollback(PackageInterface $package) { - $writer = $this->getWriter($package); - $writer->rollback(); + if ($writer = $this->getWriter($package)) { + $writer->rollback(); + } elseif ($this->io->isVerbose()) { + $this->io->write( + 'No info files found for ' .$package->getPrettyName() . '' + ); + } } /** diff --git a/tests/DrupalInfoTest.php b/tests/DrupalInfoTest.php index b5840d7..8665a30 100644 --- a/tests/DrupalInfoTest.php +++ b/tests/DrupalInfoTest.php @@ -260,4 +260,54 @@ public function testRollbackRewrite() $this->assertNotContains($info_pattern, $contents); } } + + /** + * Verifies a warning if rollback is attempted without .info file. + * + * @covers ::rollbackRewrite + */ + public function testRollbackNoInfo() + { + // Generate test files. + $this->generateDirectories(); + + // Add the .info file that will be removed. + $files = [ + $this->getDirectory() . '/module_missing_info', + ]; + + $package = $this->prophesize(PackageInterface::class); + $package->getType()->willReturn('drupal-module'); + $package->getPrettyName()->willReturn('My Module'); + $package = $package->reveal(); + $packages = [$package]; + + $local_repository = $this->prophesize(WritableRepositoryInterface::class); + $local_repository->getPackages()->willReturn($packages); + + $manager = $this->prophesize(RepositoryManager::class); + $manager->getLocalRepository()->willReturn($local_repository->reveal()); + + $installer = $this->prophesize(InstallerInterface::class); + $installer->getInstallPath($package)->willReturn($this->getDirectory() . '/module_missing_info'); + $location_manager = $this->prophesize(InstallationManager::class); + $location_manager->getInstaller('drupal-module')->willReturn($installer->reveal()); + + $this->composer = $this->prophesize(Composer::class); + $this->composer->getRepositoryManager()->willReturn($manager->reveal()); + $this->composer->getInstallationManager()->willReturn($location_manager->reveal()); + $this->composer->getConfig()->willReturn(null); + + // Ensure an error is logged. + $this->io->isVerbose()->willReturn(true); + $this->io->write('No info files found for My Module')->shouldBeCalledOnce(); + + $this->fixture->activate( + $this->composer->reveal(), + $this->io->reveal() + ); + + $event = $this->prophesize(Event::class); + $this->fixture->rollbackRewrite($event->reveal()); + } } diff --git a/tests/InfoFileTrait.php b/tests/InfoFileTrait.php index 6b972b3..6ec47ec 100644 --- a/tests/InfoFileTrait.php +++ b/tests/InfoFileTrait.php @@ -34,6 +34,9 @@ public function generateDirectories() 'module_with_version' => [ 'module_with_version.info.yml' => "name: module with version\nversion:8.x-1.0-alpha4", ], + 'module_missing_info' => [ + 'README.md' => 'A README file.' + ], ], // Drupal 7. 'drupal7' => [