public function testRemoveRootPathMappingRestoresResourcesIfSavingFails1()
{
$this->initDefaultManager();
$this->repo->expects($this->at(0))->method('remove')->with('/path1');
$this->repo->expects($this->at(1))->method('add')->with('/path1', new DirectoryResource($this->packageDir1 . '/resources'));
$this->repo->expects($this->at(2))->method('remove')->with('/path2');
$this->repo->expects($this->at(3))->method('add')->with('/path2', new DirectoryResource($this->packageDir1 . '/resources'));
// Restore: only add root mappings
$this->repo->expects($this->at(4))->method('add')->with('/path2', new DirectoryResource($this->rootDir . '/resources'));
$this->repo->expects($this->at(5))->method('add')->with('/path1', new DirectoryResource($this->rootDir . '/resources'));
$this->packageFileStorage->expects($this->once())->method('saveRootPackageFile')->willThrowException(new TestException('Cannot save'));
$this->rootPackageFile->addPathMapping($mapping1 = new PathMapping('/path1', 'resources'));
$this->rootPackageFile->addPathMapping($mapping2 = new PathMapping('/path2', 'resources'));
$this->rootPackageFile->setOverriddenPackages(array('vendor/package1'));
$this->packageFile1->addPathMapping($mapping3 = new PathMapping('/path1', 'resources'));
$this->packageFile1->addPathMapping($mapping4 = new PathMapping('/path2', 'resources'));
try {
$this->manager->removeRootPathMappings(Expr::startsWith('/path', PathMapping::REPOSITORY_PATH));
$this->fail('Expected a TestException');
} catch (TestException $e) {
}
$this->assertTrue($mapping1->isEnabled());
$this->assertTrue($mapping2->isEnabled());
$this->assertTrue($mapping3->isEnabled());
$this->assertTrue($mapping4->isEnabled());
$this->assertCount(0, $this->manager->getPathConflicts());
}