Skip to content

Commit

Permalink
Merge pull request #19 from drupal-composer/18-rollback
Browse files Browse the repository at this point in the history
Don't run rollback if missing .info files.
  • Loading branch information
jhedstrom authored Jul 16, 2019
2 parents b17a052 + 1065e1e commit 7cb6602
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 5 deletions.
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
]
}
}
9 changes: 7 additions & 2 deletions src/DrupalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<info>No info files found for ' .$package->getPrettyName() . '</info>'
);
}
}

/**
Expand Down
50 changes: 50 additions & 0 deletions tests/DrupalInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<info>No info files found for My Module</info>')->shouldBeCalledOnce();

$this->fixture->activate(
$this->composer->reveal(),
$this->io->reveal()
);

$event = $this->prophesize(Event::class);
$this->fixture->rollbackRewrite($event->reveal());
}
}
3 changes: 3 additions & 0 deletions tests/InfoFileTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down

0 comments on commit 7cb6602

Please sign in to comment.