Skip to content

Commit

Permalink
Merge pull request #993 from fredden/test-coverage-no-mutation-changes
Browse files Browse the repository at this point in the history
Improve test coverage
  • Loading branch information
localheinz authored Dec 6, 2023
2 parents a09478a + a5a835f commit 93537bc
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 11 deletions.
6 changes: 0 additions & 6 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,11 @@
<MixedAssignment>
<code>$value</code>
</MixedAssignment>
<UnusedForeachValue>
<code>$value</code>
</UnusedForeachValue>
</file>
<file src="src/Vendor/Composer/VersionConstraintNormalizer.php">
<MixedAssignment>
<code>$value</code>
</MixedAssignment>
<UnusedForeachValue>
<code>$value</code>
</UnusedForeachValue>
</file>
<file src="test/Fixture/FormatNormalizer/NormalizeNormalizesJson/Scenario.php">
<PossiblyUnusedMethod>
Expand Down
2 changes: 1 addition & 1 deletion src/Format/JsonEncodeOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function fromJson(Json $json): self
$jsonEncodeOptions = 0;

if (!\str_contains($json->encoded(), '\/')) {
$jsonEncodeOptions |= \JSON_UNESCAPED_SLASHES;
$jsonEncodeOptions = \JSON_UNESCAPED_SLASHES;
}

if (1 !== \preg_match('/(\\\\+)u([0-9a-f]{4})/i', $json->encoded())) {
Expand Down
2 changes: 1 addition & 1 deletion src/Format/NewLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private function __construct(private readonly string $value)
*/
public static function fromString(string $value): self
{
if (1 !== \preg_match('/^(?>\r\n|\n|\r)$/', $value)) {
if ("\n" !== $value && "\r" !== $value && "\r\n" !== $value) {
throw Exception\InvalidNewLineString::fromString($value);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Vendor/Composer/PackageHashNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function normalize(Json $json): Json

foreach ($objectPropertiesThatShouldBeNormalized as $name => $value) {
/** @var array<string, string> $packages */
$packages = (array) $decoded->{$name};
$packages = (array) $value;

if ([] === $packages) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/Vendor/Composer/VersionConstraintNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function normalize(Json $json): Json
}

foreach ($objectPropertiesThatShouldBeNormalized as $name => $value) {
$packages = (array) $decoded->{$name};
$packages = (array) $value;

if ([] === $packages) {
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "This test exists to cover certain mutants from infection/infection",
"require": {},
"require-dev": {
"ergebnis/overlapping-version-constraints-1": "^1.0 || 3.4.5",
"ergebnis/overlapping-version-constraints-2": "^1.0 || ^2.0",
"ergebnis/separator-mixing": "^1.0 || ^1.2 >=1.2.4 <1.2.7",
"ergebnis/whitespace-around-version": "*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"description": "This test exists to cover certain mutants from infection/infection",
"require": {},
"require-dev": {
"ergebnis/whitespace-around-version": " * ",
"ergebnis/overlapping-version-constraints-1": "3.4.5 || ^1.0 || ^1.1 || ^1.2",
"ergebnis/overlapping-version-constraints-2": "^1.0 || ^2.0 || ^1.1 || ^2.1",
"ergebnis/separator-mixing": "^1.0 | ^1.1 || ^1.2,<1.2.7 >=1.2.4 || ^1.4"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"homepage": "https://getcomposer.org/doc/04-schema.md#suggest",
"require": {},
"suggest": {
"php": "Nothing works without it",
"hhvm": "Okay",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"homepage": "https://getcomposer.org/doc/04-schema.md#suggest",
"require": {},
"suggest": {
"php": "Nothing works without it",
"hhvm": "Okay",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ext-foo": "*",
"lib-baz": "*",
"composer-plugin-api": "*",
"0-test/sort-order": "*",
"acquia/drupal-environment-detector": "*",
"ergebnis/php-cs-fixer-config": "*",
"ergebnis/test-util": "*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"acquia/drupal-environment-detector": "*",
"ext-foo": "*",
"composer-plugin-api": "*",
"0-test/sort-order": "*",
"php": "*"
}
}
2 changes: 2 additions & 0 deletions test/Unit/Format/IndentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function testFromSizeAndStyleRejectsInvalidSize(int $size): void
$style = self::faker()->randomElement(\array_keys(Format\Indent::CHARACTERS));

$this->expectException(Exception\InvalidIndentSize::class);
$this->expectExceptionMessage(\sprintf('Size needs to be greater than %d, but %d is not.', 0, $size));

Format\Indent::fromSizeAndStyle(
$size,
Expand Down Expand Up @@ -76,6 +77,7 @@ public function testFromSizeAndStyleRejectsInvalidStyle(): void
$style = $faker->sentence();

$this->expectException(Exception\InvalidIndentStyle::class);
$this->expectExceptionMessage(\sprintf('Style needs to be one of "space", "tab", but "%s" is not.', $style));

Format\Indent::fromSizeAndStyle(
$size,
Expand Down
2 changes: 1 addition & 1 deletion test/Unit/Format/JsonEncodeOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static function provideJsonEncodeOptionsAndEncoded(): array
[
\JSON_UNESCAPED_SLASHES,
'{
"name": "Andreas M\u00f6ller",
"name": "Andreas M\u00F6ller",
"url": "https://github.com/ergebnis/json-normalizer"
}',
],
Expand Down
1 change: 1 addition & 0 deletions test/Unit/Format/NewLineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class NewLineTest extends Framework\TestCase
public function testFromStringRejectsInvalidNewLineString(string $string): void
{
$this->expectException(Exception\InvalidNewLineString::class);
$this->expectExceptionMessage(\sprintf('"%s" is not a valid new-line character sequence.', $string));

Format\NewLine::fromString($string);
}
Expand Down
1 change: 1 addition & 0 deletions test/Unit/Vendor/Composer/ComposerJsonNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Ergebnis\Json\Normalizer\WithFinalNewLineNormalizer;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(SchemaNormalizer::class)]
#[Framework\Attributes\CoversClass(Vendor\Composer\BinNormalizer::class)]
#[Framework\Attributes\CoversClass(Vendor\Composer\ComposerJsonNormalizer::class)]
#[Framework\Attributes\CoversClass(Vendor\Composer\ConfigHashNormalizer::class)]
Expand Down

0 comments on commit 93537bc

Please sign in to comment.