diff --git a/src/MezzioInstaller/OptionalPackages.php b/src/MezzioInstaller/OptionalPackages.php index ce2c721..0303921 100644 --- a/src/MezzioInstaller/OptionalPackages.php +++ b/src/MezzioInstaller/OptionalPackages.php @@ -211,6 +211,7 @@ public static function install(Event $event): void $installer->io->write('Setting up optional packages'); $installer->setupDataAndCacheDir(); + $installer->removeLockfile(); $installer->removeDevDependencies(); $installer->setInstallType($installer->requestInstallType()); $installer->setupDefaultApp(); @@ -253,6 +254,20 @@ public function setupDataAndCacheDir(): void } } + /** + * Remove composer lockfile. + * + * Installer adds and removes dependencies which invalidates lockfile. + * Dependencies locked in existing lockfile are dependent on PHP version where it was created. + */ + public function removeLockfile(): void + { + if (is_file($this->projectRoot . '/composer.lock')) { + $this->io->write('Removing composer.lock'); + unlink($this->projectRoot . '/composer.lock'); + } + } + /** * Cleanup development dependencies. * diff --git a/test/MezzioInstallerTest/RemoveLockfileTest.php b/test/MezzioInstallerTest/RemoveLockfileTest.php new file mode 100644 index 0000000..3a332e1 --- /dev/null +++ b/test/MezzioInstallerTest/RemoveLockfileTest.php @@ -0,0 +1,48 @@ +project = vfsStream::setup('project-root'); + $this->projectRoot = vfsStream::url('project-root'); + $this->installer = $this->createOptionalPackages($this->projectRoot); + } + + public function testRemovesLockfileWhenInvoked(): void + { + vfsStream::newFile('composer.lock')->at($this->project)->withContent('{}'); + $this->io + ->expects($this->once()) + ->method('write') + ->with($this->stringContains('Removing composer.lock')); + $this->installer->removeLockfile(); + + self::assertFalse($this->project->hasChild('composer.lock'), 'Lockfile was not deleted'); + } + + public function testNoopWhenNoLockfileExists(): void + { + self::assertFalse($this->project->hasChild('composer.lock')); + $this->io + ->expects($this->never()) + ->method('write'); + $this->installer->removeLockfile(); + } +}