Skip to content

Commit

Permalink
Add installer step removing lockfile
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksei Khudiakov <aleksey@xerkus.pro>
  • Loading branch information
Xerkus committed Jan 9, 2024
1 parent 7f22e4f commit 3d1a45e
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/MezzioInstaller/OptionalPackages.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public static function install(Event $event): void
$installer->io->write('<info>Setting up optional packages</info>');

$installer->setupDataAndCacheDir();
$installer->removeLockfile();
$installer->removeDevDependencies();
$installer->setInstallType($installer->requestInstallType());
$installer->setupDefaultApp();
Expand Down Expand Up @@ -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('<info>Removing composer.lock</info>');
unlink($this->projectRoot . '/composer.lock');
}
}

/**
* Cleanup development dependencies.
*
Expand Down
48 changes: 48 additions & 0 deletions test/MezzioInstallerTest/RemoveLockfileTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace MezzioInstallerTest;

use MezzioInstaller\OptionalPackages;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;

class RemoveLockfileTest extends OptionalPackagesTestCase
{
private OptionalPackages $installer;

private vfsStreamDirectory $project;

/** @var string URL of project root */
private string $projectRoot;

protected function setUp(): void
{
parent::setUp();
$this->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();
}
}

0 comments on commit 3d1a45e

Please sign in to comment.