Skip to content

Commit db85ca8

Browse files
committed
Kill mutants
1 parent 77e395b commit db85ca8

13 files changed

+83
-39
lines changed

src/SourceLocator/Type/AutoloadSourceLocator/FileReadTrapStreamWrapper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function withStreamWrapperOverride(
7272
$result = $executeMeWithinStreamWrapperOverride();
7373
} finally {
7474
foreach ($streamWrapperProtocols as $protocol) {
75-
stream_wrapper_restore($protocol);
75+
@stream_wrapper_restore($protocol);
7676
}
7777

7878
self::$registeredStreamWrapperProtocols = null;
@@ -130,7 +130,7 @@ public function url_stat($path, $flags): array|bool
130130
stream_wrapper_restore($protocol);
131131
}
132132

133-
if ($flags & STREAM_URL_STAT_QUIET) {
133+
if (($flags & STREAM_URL_STAT_QUIET) === STREAM_URL_STAT_QUIET) {
134134
$result = @stat($path);
135135
} else {
136136
$result = stat($path);

src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJson.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use function is_array;
2626
use function is_dir;
2727
use function is_file;
28+
use function is_string;
2829
use function json_decode;
2930
use function realpath;
3031

@@ -61,8 +62,11 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
6162
throw MissingComposerJson::inProjectPath($installationPath);
6263
}
6364

65+
$composerJsonContent = file_get_contents($composerJsonPath);
66+
assert(is_string($composerJsonContent));
67+
6468
/** @psalm-var array{autoload: ComposerAutoload}|null $composer */
65-
$composer = json_decode((string) file_get_contents($composerJsonPath), true);
69+
$composer = json_decode($composerJsonContent, true);
6670

6771
if (! is_array($composer)) {
6872
throw FailedToParseJson::inFile($composerJsonPath);

src/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerJsonAndInstalledJson.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use function is_array;
2828
use function is_dir;
2929
use function is_file;
30+
use function is_string;
3031
use function json_decode;
3132
use function realpath;
3233
use function rtrim;
@@ -52,8 +53,11 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
5253
throw MissingComposerJson::inProjectPath($installationPath);
5354
}
5455

56+
$composerJsonContent = file_get_contents($composerJsonPath);
57+
assert(is_string($composerJsonContent));
58+
5559
/** @psalm-var Composer|null $composer */
56-
$composer = json_decode((string) file_get_contents($composerJsonPath), true);
60+
$composer = json_decode($composerJsonContent, true);
5761
$vendorDir = $composer['config']['vendor-dir'] ?? 'vendor';
5862
$vendorDir = rtrim($vendorDir, '/');
5963

@@ -63,8 +67,11 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
6367
throw MissingInstalledJson::inProjectPath($realInstallationPath . '/' . $vendorDir);
6468
}
6569

70+
$jsonContent = file_get_contents($installedJsonPath);
71+
assert(is_string($jsonContent));
72+
6673
/** @psalm-var array{packages: list<mixed[]>}|list<mixed[]>|null $installedJson */
67-
$installedJson = json_decode((string) file_get_contents($installedJsonPath), true);
74+
$installedJson = json_decode($jsonContent, true);
6875

6976
if (! is_array($composer)) {
7077
throw FailedToParseJson::inFile($composerJsonPath);

src/SourceLocator/Type/Composer/Factory/MakeLocatorForInstalledJson.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use function is_array;
2828
use function is_dir;
2929
use function is_file;
30+
use function is_string;
3031
use function json_decode;
3132
use function realpath;
3233
use function rtrim;
@@ -52,8 +53,11 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
5253
throw MissingComposerJson::inProjectPath($installationPath);
5354
}
5455

56+
$composerJsonContent = file_get_contents($composerJsonPath);
57+
assert(is_string($composerJsonContent));
58+
5559
/** @psalm-var Composer|null $composer */
56-
$composer = json_decode((string) file_get_contents($composerJsonPath), true);
60+
$composer = json_decode($composerJsonContent, true);
5761
$vendorDir = $composer['config']['vendor-dir'] ?? 'vendor';
5862
$vendorDir = rtrim($vendorDir, '/');
5963

@@ -63,8 +67,11 @@ public function __invoke(string $installationPath, Locator $astLocator): SourceL
6367
throw MissingInstalledJson::inProjectPath($realInstallationPath . '/' . $vendorDir);
6468
}
6569

70+
$jsonContent = file_get_contents($installedJsonPath);
71+
assert(is_string($jsonContent));
72+
6673
/** @var array{packages: list<mixed[]>}|list<mixed[]>|null $installedJson */
67-
$installedJson = json_decode((string) file_get_contents($installedJsonPath), true);
74+
$installedJson = json_decode($jsonContent, true);
6875

6976
if (! is_array($installedJson)) {
7077
throw FailedToParseJson::inFile($installedJsonPath);

src/SourceLocator/Type/FileIteratorSourceLocator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __construct(Iterator $fileInfoIterator, private Locator $astLoca
5353
/** @throws InvalidFileLocation */
5454
private function getAggregatedSourceLocator(): AggregateSourceLocator
5555
{
56+
// @infection-ignore-all Coalesce: There's no difference, it's just optimization
5657
return $this->aggregateSourceLocator
5758
?? $this->aggregateSourceLocator = new AggregateSourceLocator(array_values(array_filter(array_map(
5859
function (SplFileInfo $item): SingleFileSourceLocator|null {

src/Util/FileHelper.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use function assert;
88
use function preg_match;
9+
use function sprintf;
910
use function str_replace;
1011

1112
use const DIRECTORY_SEPARATOR;
@@ -43,13 +44,14 @@ public static function normalizeSystemPath(string $originalPath): string
4344
[, $scheme, $path] = $matches;
4445
}
4546

47+
// @infection-ignore-all Identical Needed only on Windows
4648
if (DIRECTORY_SEPARATOR === '\\') {
4749
// @infection-ignore-all UnwrapStrReplace Needed only on Windows
4850
$path = str_replace('/', DIRECTORY_SEPARATOR, $path);
4951
}
5052

5153
assert($path !== '');
5254

53-
return ($scheme !== null ? $scheme . '://' : '') . $path;
55+
return ($scheme !== null ? sprintf('%s://', $scheme) : '') . $path;
5456
}
5557
}

test/unit/Fixture/InitializedProperties.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public function __construct()
2424

2525
public function __get($property)
2626
{
27-
throw new Error();
27+
throw new Error('Removed property');
2828
}
2929
}

test/unit/Reflection/ReflectionPropertyTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ public function testIsInitializedThrowsError(): void
778778
$classReflection = $this->reflector->reflectClass(InitializedProperties::class);
779779

780780
self::expectException(Error::class);
781+
self::expectExceptionMessage('Removed property');
781782
$classReflection->getProperty('toBeRemoved')->isInitialized($object);
782783
}
783784

test/unit/SourceLocator/Type/AutoloadSourceLocator/FileReadTrapStreamWrapperTest.php

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313

1414
use function file_get_contents;
1515
use function is_file;
16+
use function restore_error_handler;
17+
use function set_error_handler;
1618
use function sprintf;
1719
use function uniqid;
1820

21+
use const E_WARNING;
22+
1923
/**
2024
* @covers \Roave\BetterReflection\SourceLocator\Type\AutoloadSourceLocator\FileReadTrapStreamWrapper
2125
*
@@ -177,28 +181,38 @@ static function () use ($thrown): string {
177181

178182
public function testWillRaiseWarningWhenTryingToCheckFileExistenceForNonExistingFileWithoutSilencingModifier(): void
179183
{
184+
set_error_handler(static function (int $errno, string $errstr): bool {
185+
throw new Exception($errstr, $errno);
186+
}, E_WARNING);
187+
180188
$nonExistingFile = __DIR__ . uniqid('non-existing-file', true);
181189

182-
self::assertSame(
183-
'another value produced by the function',
184-
FileReadTrapStreamWrapper::withStreamWrapperOverride(
185-
static function () use ($nonExistingFile): string {
186-
if (is_file($nonExistingFile)) {
187-
throw new UnexpectedValueException('is_file() should report `false` for a non-existing file');
188-
}
190+
self::expectExceptionMessageMatches('~stat\(\): stat failed for~');
189191

190-
if (@file_get_contents($nonExistingFile) !== false) {
191-
throw new UnexpectedValueException('file_get_contents() should report `false` for a non-existing file');
192-
}
192+
try {
193+
self::assertSame(
194+
'another value produced by the function',
195+
FileReadTrapStreamWrapper::withStreamWrapperOverride(
196+
static function () use ($nonExistingFile): string {
197+
if (is_file($nonExistingFile)) {
198+
throw new UnexpectedValueException('is_file() should report `false` for a non-existing file');
199+
}
193200

194-
return 'another value produced by the function';
195-
},
196-
['file'],
197-
),
198-
);
201+
if (file_get_contents($nonExistingFile) !== false) {
202+
throw new UnexpectedValueException('file_get_contents() should report `false` for a non-existing file');
203+
}
199204

200-
self::assertNull(FileReadTrapStreamWrapper::$autoloadLocatedFile);
201-
self::assertNotEmpty(file_get_contents(__FILE__), 'Stream wrapper was removed, file reads work again');
205+
return 'another value produced by the function';
206+
},
207+
['file'],
208+
),
209+
);
210+
} finally {
211+
self::assertNull(FileReadTrapStreamWrapper::$autoloadLocatedFile);
212+
self::assertNotEmpty(file_get_contents(__FILE__), 'Stream wrapper was removed, file reads work again');
213+
214+
restore_error_handler();
215+
}
202216
}
203217

204218
public function testUrlStatThrowsExceptionWhenCalledDirectly(): void

test/unit/SourceLocator/Type/Composer/Factory/MakeLocatorForComposerInstalledJsonTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ public function testWillFailToProduceLocatorForProjectWithoutComposerJson(): voi
268268
public function testWillFailToProduceLocatorForProjectWithoutInstalledJson(): void
269269
{
270270
$this->expectException(MissingInstalledJson::class);
271+
$this->expectExceptionMessageMatches('~^Could not locate a "composer/installed.json" file in "[^"]+[\\\\/]Assets[\\\\/]ComposerLocators[\\\\/]project-without-installed.json/vendor"$~');
271272

272273
(new MakeLocatorForInstalledJson())
273274
->__invoke(

0 commit comments

Comments
 (0)