Skip to content

Commit d67cf48

Browse files
committed
refactor: improve line-ending checks
1 parent 0f3932c commit d67cf48

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

tests/LibraryStarterKit/WindowsSafeTextDriver.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use PHPUnit\Framework\Assert;
88
use Spatie\Snapshots\Driver;
99

10+
use function assert;
11+
use function is_string;
1012
use function preg_replace;
1113

1214
/**
@@ -15,35 +17,26 @@
1517
*/
1618
class WindowsSafeTextDriver implements Driver
1719
{
18-
/**
19-
* @param string $data
20-
*
21-
* @inheritDoc
22-
*/
23-
public function serialize($data): string
20+
public function serialize(mixed $data): string
2421
{
25-
// Save snapshot only with lf line endings.
26-
$data = (string) preg_replace('/\r\n/', "\n", $data);
22+
assert(is_string($data));
2723

28-
return $data;
24+
// Save snapshot only with lf line endings.
25+
return (string) preg_replace('/\R/', "\n", $data);
2926
}
3027

3128
public function extension(): string
3229
{
3330
return 'txt';
3431
}
3532

36-
/**
37-
* @param string $expected
38-
* @param string $actual
39-
*
40-
* @inheritDoc
41-
*/
42-
public function match($expected, $actual): void
33+
public function match(mixed $expected, mixed $actual): void
4334
{
35+
assert(is_string($expected));
36+
4437
// Make sure the expected string has lf line endings, so we can
4538
// compare accurately.
46-
$expected = (string) preg_replace('/\r\n/', "\n", $expected);
39+
$expected = (string) preg_replace('/\R/', "\n", $expected);
4740

4841
Assert::assertEquals($expected, $this->serialize($actual));
4942
}

0 commit comments

Comments
 (0)