Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Dec 16, 2023
1 parent 6f918b0 commit 5dcfec2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1826,11 +1826,14 @@ private static function retrieveComposerArtifact(string $path): ?ComposerArtifac
}

try {
$contents = json_decode($path, true);
$contents = json_decode(
FS::getFileContents($path),
true,
);
} catch (JsonException $exception) {
throw new InvalidArgumentException(
sprintf(
'Expected the file "%s" to be a valid composer.json file but an error has been found: %s',
'Expected the file "%s" to be a valid JSON file but an error has been found: %s',
$path,
$exception->getMessage(),
),
Expand Down
24 changes: 7 additions & 17 deletions tests/Configuration/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use DateTimeInterface;
use Fidry\FileSystem\FS;
use InvalidArgumentException;
use JsonException;
use KevinGH\Box\Compactor\InvalidCompactor;
use KevinGH\Box\Compactor\NullCompactor;
use KevinGH\Box\Compactor\Php;
Expand All @@ -34,7 +35,6 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use RuntimeException;
use Seld\JsonLint\ParsingException;
use stdClass;
use function abs;
use function array_fill_keys;
Expand Down Expand Up @@ -356,17 +356,12 @@ public function test_it_throws_an_error_when_a_composer_file_is_found_but_invali
} catch (InvalidArgumentException $exception) {
$composerJson = $this->tmp.'/composer.json';

self::assertSame(
<<<EOF
Expected the file "{$composerJson}" to be a valid composer.json file but an error has been found: Parse error on line 1:
^
Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
EOF,
self::assertStringStartsWith(
"Expected the file \"{$composerJson}\" to be a valid JSON file but an error has been found: ",
$exception->getMessage(),
);
self::assertSame(0, $exception->getCode());
self::assertInstanceOf(ParsingException::class, $exception->getPrevious());
self::assertInstanceOf(JsonException::class, $exception->getPrevious());
}
}

Expand All @@ -381,17 +376,12 @@ public function test_it_throws_an_error_when_a_composer_lock_is_found_but_invali
} catch (InvalidArgumentException $exception) {
$composerLock = $this->tmp.'/composer.lock';

self::assertSame(
<<<EOF
Expected the file "{$composerLock}" to be a valid composer.json file but an error has been found: Parse error on line 1:
^
Expected one of: 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
EOF,
self::assertStringStartsWith(
"Expected the file \"{$composerLock}\" to be a valid JSON file but an error has been found: ",
$exception->getMessage(),
);
self::assertSame(0, $exception->getCode());
self::assertInstanceOf(ParsingException::class, $exception->getPrevious());
self::assertInstanceOf(JsonException::class, $exception->getPrevious());
}
}

Expand Down

0 comments on commit 5dcfec2

Please sign in to comment.