Skip to content

Commit 08a9953

Browse files
Merge pull request #97 from vhenzl/win-eol-fix
Fix inconsistent line endings in JSON snapshots
2 parents 8b8e881 + ab7311d commit 08a9953

File tree

9 files changed

+41
-35
lines changed

9 files changed

+41
-35
lines changed

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
/.scrutinizer.yml export-ignore
1010
/tests export-ignore
1111
/example export-ignore
12+
13+
# All test snapshots and text stubs must have LF line endings
14+
tests/**/__snapshots__/** text eol=lf
15+
tests/**/stubs/** text eol=lf
16+
tests/**/stubs/**/*.jpg binary
17+
tests/**/stubs/**/*.png binary

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
fail-fast: true
1111
matrix:
12-
os: [ubuntu-latest]
12+
os: [ubuntu-latest, windows-latest]
1313
php: [7.4]
1414
dependency-version: [prefer-lowest, prefer-stable]
1515

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
}
4343
},
4444
"scripts": {
45-
"test": "vendor/bin/phpunit"
45+
"test": "phpunit"
4646
},
4747
"config": {
4848
"sort-packages": true

src/Drivers/JsonDriver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function serialize($data): string
1818
throw new CantBeSerialized('Resources can not be serialized to json');
1919
}
2020

21-
return json_encode($data, JSON_PRETTY_PRINT).PHP_EOL;
21+
return json_encode($data, JSON_PRETTY_PRINT)."\n";
2222
}
2323

2424
public function extension(): string
@@ -29,7 +29,7 @@ public function extension(): string
2929
public function match($expected, $actual)
3030
{
3131
if (is_array($actual)) {
32-
$actual = json_encode($actual, JSON_PRETTY_PRINT).PHP_EOL;
32+
$actual = json_encode($actual, JSON_PRETTY_PRINT)."\n";
3333
}
3434

3535
Assert::assertJsonStringEqualsJsonString($expected, $actual);

tests/Unit/Drivers/HtmlDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function it_can_serialize_a_html_string_to_pretty_html()
1313
{
1414
$driver = new HtmlDriver();
1515

16-
$expected = implode(PHP_EOL, [
16+
$expected = implode("\n", [
1717
'<!DOCTYPE html>',
1818
'<html lang="en">',
1919
'<head></head>',

tests/Unit/Drivers/JsonDriverTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function it_can_serialize_a_json_string_to_pretty_json()
1313
{
1414
$driver = new JsonDriver();
1515

16-
$expected = implode(PHP_EOL, [
16+
$expected = implode("\n", [
1717
'{',
1818
' "foo": "bar"',
1919
'}',
@@ -28,7 +28,7 @@ public function it_can_serialize_a_json_hash_to_pretty_json()
2828
{
2929
$driver = new JsonDriver();
3030

31-
$expected = implode(PHP_EOL, [
31+
$expected = implode("\n", [
3232
'{',
3333
' "foo": "FOO",',
3434
' "bar": "BAR",',
@@ -42,7 +42,7 @@ public function it_can_serialize_a_json_hash_to_pretty_json()
4242
'baz' => 'BAZ',
4343
]));
4444

45-
$expected = implode(PHP_EOL, [
45+
$expected = implode("\n", [
4646
'{',
4747
' "foo": "FOO",',
4848
' "bar": "BAR",',
@@ -74,7 +74,7 @@ public function it_can_serialize_a_json_array_to_pretty_json()
7474
{
7575
$driver = new JsonDriver();
7676

77-
$expected = implode(PHP_EOL, [
77+
$expected = implode("\n", [
7878
'[',
7979
' "foo",',
8080
' "bar",',
@@ -91,7 +91,7 @@ public function it_can_serialize_a_empty_json_object_to_pretty_json()
9191
{
9292
$driver = new JsonDriver();
9393

94-
$expected = implode(PHP_EOL, [
94+
$expected = implode("\n", [
9595
'{',
9696
' "foo": {',
9797
' "bar": true',
@@ -116,7 +116,7 @@ public function it_can_not_serialize_resources()
116116

117117
$this->expectException(CantBeSerialized::class);
118118

119-
$resource = fopen('.', 'r');
119+
$resource = tmpfile();
120120

121121
$driver->serialize($resource);
122122
}

tests/Unit/Drivers/ObjectDriverTest.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public function it_can_serialize_an_associative_array()
3636
{
3737
$driver = new ObjectDriver();
3838

39-
$expected = <<<'YAML'
40-
foo:
41-
bar: baz
42-
43-
YAML;
39+
$expected = implode("\n", [
40+
'foo:',
41+
' bar: baz',
42+
'',
43+
]);
4444

4545
$this->assertEquals($expected, $driver->serialize(['foo' => ['bar' => 'baz']]));
4646
}
@@ -50,11 +50,11 @@ public function it_can_serialize_an_indexed_array_without_keys()
5050
{
5151
$driver = new ObjectDriver();
5252

53-
$expected = <<<'YAML'
54-
- foo
55-
- bar
56-
57-
YAML;
53+
$expected = implode("\n", [
54+
'- foo',
55+
'- bar',
56+
'',
57+
]);
5858

5959
$this->assertEquals($expected, $driver->serialize(['foo', 'bar']));
6060
}
@@ -64,10 +64,10 @@ public function it_can_serialize_a_simple_object()
6464
{
6565
$driver = new ObjectDriver();
6666

67-
$expected = <<<'YAML'
68-
foo: bar
69-
70-
YAML;
67+
$expected = implode("\n", [
68+
'foo: bar',
69+
'',
70+
]);
7171

7272
$this->assertEquals($expected, $driver->serialize((object) ['foo' => 'bar']));
7373
}
@@ -77,13 +77,13 @@ public function it_can_serialize_a_class_instance()
7777
{
7878
$driver = new ObjectDriver();
7979

80-
$expected = <<<'YAML'
81-
name: 'My name'
82-
valid: true
83-
dateTime: '2020-01-01T15:00:00+01:00'
84-
public: public
85-
86-
YAML;
80+
$expected = implode("\n", [
81+
'name: \'My name\'',
82+
'valid: true',
83+
'dateTime: \'2020-01-01T15:00:00+01:00\'',
84+
'public: public',
85+
'',
86+
]);
8787

8888
$this->assertEquals($expected, $driver->serialize(new Obj()));
8989
}

tests/Unit/Drivers/XmlDriverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public function it_can_serialize_a_xml_string_to_pretty_xml()
1313
{
1414
$driver = new XmlDriver();
1515

16-
$expected = implode(PHP_EOL, [
16+
$expected = implode("\n", [
1717
'<?xml version="1.0"?>',
1818
'<foo>',
1919
' <bar>baz</bar>',

tests/Unit/Drivers/YamlDriverTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public function it_can_serialize_a_yaml_string()
1212
{
1313
$driver = new YamlDriver();
1414

15-
$yamlString = implode(PHP_EOL, [
15+
$yamlString = implode("\n", [
1616
'foo: bar',
1717
'baz: qux',
1818
'',
@@ -26,7 +26,7 @@ public function it_can_serialize_a_yaml_array()
2626
{
2727
$driver = new YamlDriver();
2828

29-
$expected = implode(PHP_EOL, [
29+
$expected = implode("\n", [
3030
'foo: bar',
3131
'baz: qux',
3232
'',

0 commit comments

Comments
 (0)