1
0
Fork 0

Fix tests on Windows

pull/11517/head
Dan Wallis 2023-06-21 14:46:36 +01:00
parent af4ae5a7a7
commit 5b98f74e49
No known key found for this signature in database
GPG Key ID: A02198884F2740BC
5 changed files with 2258 additions and 24 deletions

View File

@ -318,12 +318,12 @@ class JsonFile
}
$data = json_decode($json, true);
if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
$lines = explode(PHP_EOL, $json);
$lines = explode("\n", $json);
if (isset($lines[9]) && strpos($lines[9], '"content-hash": "') !== false && strpos($lines[7], '"content-hash": "') !== false) {
// We may have found a git merge conflict in composer.lock. Remove the offending lines and try again.
unset($lines[6], $lines[7], $lines[9], $lines[10]);
$lines[8] = ' "content-hash": "VCS merge conflict detected. Please run `composer update --lock`.",';
return self::parseJson(implode(PHP_EOL, $lines), $file);
return self::parseJson(implode("\n", $lines), $file);
}
self::validateSyntax($json, $file);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,22 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
<<<<<<< HEAD
"content-hash": "e0281a92ffdb4118e47df762a8e80d8d",
=======
"content-hash": "19ff2417ff3290c12442b3d170de974e",
>>>>>>> branch-name
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View File

@ -0,0 +1,22 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
<<<<<<< HEAD
"content-hash": "e0281a92ffdb4118e47df762a8e80d8d",
=======
"content-hash": "19ff2417ff3290c12442b3d170de974e",
>>>>>>> branch-name
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}

View File

@ -385,28 +385,33 @@ class JsonFileTest extends TestCase
'plugin-api-version' => '2.3.0',
];
$json = '{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
<<<<<<< HEAD
"content-hash": "e0281a92ffdb4118e47df762a8e80d8d",
=======
"content-hash": "19ff2417ff3290c12442b3d170de974e",
>>>>>>> branch-name
"packages": [],
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],
"platform-dev": [],
"plugin-api-version": "2.3.0"
}';
$json = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-simple.txt');
$this->assertEquals($data, JsonFile::parseJson($json));
}
public function testComposerLockFileMergeConflictSimpleCRLF(): void
{
$data = [
'_readme' => [
'This file locks the dependencies of your project to a known state',
'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies',
'This file is @generated automatically',
],
'content-hash' => 'VCS merge conflict detected. Please run `composer update --lock`.',
'packages' => [],
'packages-dev' => [],
'aliases' => [],
'minimum-stability' => "stable",
'stability-flags' => [],
'prefer-stable' => false,
'prefer-lowest' => false,
'platform' => [],
'platform-dev' => [],
'plugin-api-version' => '2.3.0',
];
$json = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-simple.txt');
$this->assertEquals($data, JsonFile::parseJson($json));
}
@ -421,6 +426,16 @@ class JsonFileTest extends TestCase
JsonFile::parseJson($data);
}
public function testComposerLockFileMergeConflictComplexCRLF(): void
{
$data = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-complex-crlf.txt');
$this->expectException(ParsingException::class);
// We don't care here what the error message says, just that there is an exception thrown.
// Other tests verify that the message text is sensible.
JsonFile::parseJson($data);
}
private function expectParseException(string $text, string $json): void
{
try {