Fix tests on Windows
parent
af4ae5a7a7
commit
5b98f74e49
|
@ -318,12 +318,12 @@ class JsonFile
|
||||||
}
|
}
|
||||||
$data = json_decode($json, true);
|
$data = json_decode($json, true);
|
||||||
if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
|
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) {
|
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.
|
// 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]);
|
unset($lines[6], $lines[7], $lines[9], $lines[10]);
|
||||||
$lines[8] = ' "content-hash": "VCS merge conflict detected. Please run `composer update --lock`.",';
|
$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);
|
self::validateSyntax($json, $file);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -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"
|
||||||
|
}
|
|
@ -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"
|
||||||
|
}
|
|
@ -385,28 +385,33 @@ class JsonFileTest extends TestCase
|
||||||
'plugin-api-version' => '2.3.0',
|
'plugin-api-version' => '2.3.0',
|
||||||
];
|
];
|
||||||
|
|
||||||
$json = '{
|
$json = (string) file_get_contents(__DIR__ . '/Fixtures/composer-lock-merge-conflict-simple.txt');
|
||||||
"_readme": [
|
|
||||||
"This file locks the dependencies of your project to a known state",
|
$this->assertEquals($data, JsonFile::parseJson($json));
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
}
|
||||||
"This file is @generated automatically"
|
|
||||||
],
|
public function testComposerLockFileMergeConflictSimpleCRLF(): void
|
||||||
<<<<<<< HEAD
|
{
|
||||||
"content-hash": "e0281a92ffdb4118e47df762a8e80d8d",
|
$data = [
|
||||||
=======
|
'_readme' => [
|
||||||
"content-hash": "19ff2417ff3290c12442b3d170de974e",
|
'This file locks the dependencies of your project to a known state',
|
||||||
>>>>>>> branch-name
|
'Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies',
|
||||||
"packages": [],
|
'This file is @generated automatically',
|
||||||
"packages-dev": [],
|
],
|
||||||
"aliases": [],
|
'content-hash' => 'VCS merge conflict detected. Please run `composer update --lock`.',
|
||||||
"minimum-stability": "stable",
|
'packages' => [],
|
||||||
"stability-flags": [],
|
'packages-dev' => [],
|
||||||
"prefer-stable": false,
|
'aliases' => [],
|
||||||
"prefer-lowest": false,
|
'minimum-stability' => "stable",
|
||||||
"platform": [],
|
'stability-flags' => [],
|
||||||
"platform-dev": [],
|
'prefer-stable' => false,
|
||||||
"plugin-api-version": "2.3.0"
|
'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));
|
$this->assertEquals($data, JsonFile::parseJson($json));
|
||||||
}
|
}
|
||||||
|
@ -421,6 +426,16 @@ class JsonFileTest extends TestCase
|
||||||
JsonFile::parseJson($data);
|
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
|
private function expectParseException(string $text, string $json): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in New Issue