1
0
mirror of synced 2024-11-21 21:06:07 +03:00

fix incorrect composer.json patching (#106)

This commit is contained in:
Pavel 2021-07-20 16:37:00 +03:00 committed by GitHub
parent 1bdf8be34c
commit d7c36b2cc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 4 deletions

View File

@ -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']));
}
}

View File

@ -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__, '..', '..', '..']));
}
}

View File

@ -32,7 +32,6 @@ class ComposerLocatorTest extends TestCase
{
$file = ComposerLocator::findComposerJson();
self::assertStringContainsString('composer.json', $file);
self::assertFileExists($file);
self::assertEmpty($file);
}
}