fix incorrect composer.json patching (#106)
This commit is contained in:
parent
1bdf8be34c
commit
d7c36b2cc7
@ -58,8 +58,10 @@ class ComposerLocator
|
||||
$dir = static::getBaseDirectory();
|
||||
|
||||
for (;;) {
|
||||
if (file_exists($dir . '/composer.json')) {
|
||||
return $dir . '/composer.json';
|
||||
$fileName = implode(DIRECTORY_SEPARATOR, [$dir, 'composer.json']);
|
||||
|
||||
if (file_exists($fileName) && static::getPackageComposerJson() !== $fileName) {
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
$counter++;
|
||||
@ -80,4 +82,14 @@ class ComposerLocator
|
||||
{
|
||||
return (string) realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns full path to the composer.json of this package.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function getPackageComposerJson(): string
|
||||
{
|
||||
return (string) realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', 'composer.json']));
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,37 @@ use Symfony\Component\Console\Tester\CommandTester;
|
||||
*/
|
||||
class CompilerPromptCommandTest extends TestCase
|
||||
{
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
$packageComposerJson = implode(DIRECTORY_SEPARATOR, [static::getBaseDirectory(), 'composer.json']);
|
||||
$fileName = implode(DIRECTORY_SEPARATOR, [static::getBaseDirectory(), '..', 'composer.json']);
|
||||
|
||||
if (!file_exists($packageComposerJson)) {
|
||||
self::fail(sprintf('%s does not exist which should not happen at all. Aborting.', $packageComposerJson));
|
||||
}
|
||||
|
||||
if (
|
||||
file_exists(($fileName)) &&
|
||||
(
|
||||
filesize($fileName) !== filesize($packageComposerJson) ||
|
||||
md5_file($fileName) !== md5_file($packageComposerJson)
|
||||
)
|
||||
) {
|
||||
self::fail(sprintf('%s exists, cannot proceed with tests.', (string) realpath($fileName)));
|
||||
}
|
||||
|
||||
copy($packageComposerJson, $fileName);
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass(): void
|
||||
{
|
||||
$fileName = implode(DIRECTORY_SEPARATOR, [static::getBaseDirectory(), '..', 'composer.json']);
|
||||
|
||||
if (file_exists(($fileName))) {
|
||||
unlink($fileName);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDeactivate(): void
|
||||
{
|
||||
$tester = new CommandTester(new CompilerPromptCommand());
|
||||
@ -67,4 +98,12 @@ class CompilerPromptCommandTest extends TestCase
|
||||
|
||||
return json_decode((string) file_get_contents($composerJson), true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private static function getBaseDirectory(): string
|
||||
{
|
||||
return (string) realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..']));
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ class ComposerLocatorTest extends TestCase
|
||||
{
|
||||
$file = ComposerLocator::findComposerJson();
|
||||
|
||||
self::assertStringContainsString('composer.json', $file);
|
||||
self::assertFileExists($file);
|
||||
self::assertEmpty($file);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user