Skip to content

Commit 6561ca0

Browse files
Support PHPUnit 5.7 closes #18
1 parent efbfef5 commit 6561ca0

File tree

5 files changed

+23
-13
lines changed

5 files changed

+23
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"require": {
2323
"php": "^7.0",
24-
"phpunit/phpunit": "^6.0"
24+
"phpunit/phpunit": "^5.7|^6.0"
2525
},
2626
"autoload": {
2727
"psr-4": {

src/Drivers/JsonDriver.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ public function extension(): string
2525

2626
public function match($expected, $actual)
2727
{
28-
Assert::assertJson($expected);
29-
Assert::assertJson($actual);
30-
31-
Assert::assertThat($actual, new JsonMatches($expected));
28+
Assert::assertJsonStringEqualsJsonString($actual, $expected);
3229
}
3330
}

src/Drivers/XmlDriver.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use DOMDocument;
66
use PHPUnit\Framework\Assert;
7-
use PHPUnit\Util\Xml;
87
use Spatie\Snapshots\Driver;
98
use Spatie\Snapshots\Exceptions\CantBeSerialized;
109

@@ -32,6 +31,6 @@ public function extension(): string
3231

3332
public function match($expected, $actual)
3433
{
35-
Assert::assertEquals(Xml::load($expected), Xml::load($actual));
34+
Assert::assertXmlStringEqualsXmlString($expected, $actual);
3635
}
3736
}

src/MatchesSnapshots.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Spatie\Snapshots;
44

5+
use PHPUnit_Framework_ExpectationFailedException;
56
use PHPUnit\Framework\ExpectationFailedException;
67
use ReflectionClass;
78
use Spatie\Snapshots\Drivers\JsonDriver;
@@ -100,6 +101,10 @@ protected function doSnapshotAssertion($actual, Driver $driver)
100101
} catch (ExpectationFailedException $exception) {
101102
$snapshot->create($actual);
102103

104+
return $this->markTestIncomplete("Snapshot updated for {$snapshot->id()}");
105+
} catch (PHPUnit_Framework_ExpectationFailedException $exception) {
106+
$snapshot->create($actual);
107+
103108
return $this->markTestIncomplete("Snapshot updated for {$snapshot->id()}");
104109
}
105110
}

tests/Integration/MatchesSnapshotTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Spatie\Snapshots\Test\Integration;
44

5-
use PHPUnit\Framework\ExpectationFailedException;
65
use PHPUnit\Framework\TestCase;
6+
use PHPUnit\Runner\Version;
77
use PHPUnit_Framework_MockObject_MockObject;
88
use Spatie\Snapshots\MatchesSnapshots;
99

@@ -98,7 +98,7 @@ public function it_can_mismatch_a_string_snapshot()
9898
{
9999
$mockTrait = $this->getMatchesSnapshotMock();
100100

101-
$this->expectException(ExpectationFailedException::class);
101+
$this->expectFailedMatchesSnapshotTest();
102102

103103
$mockTrait->assertMatchesSnapshot('Bar');
104104
}
@@ -108,7 +108,7 @@ public function it_can_mismatch_a_xml_snapshot()
108108
{
109109
$mockTrait = $this->getMatchesSnapshotMock();
110110

111-
$this->expectException(ExpectationFailedException::class);
111+
$this->expectFailedMatchesSnapshotTest();
112112

113113
$mockTrait->assertMatchesXmlSnapshot('<foo><bar>Foo</bar></foo>');
114114
}
@@ -118,7 +118,7 @@ public function it_can_mismatch_a_json_snapshot()
118118
{
119119
$mockTrait = $this->getMatchesSnapshotMock();
120120

121-
$this->expectException(ExpectationFailedException::class);
121+
$this->expectFailedMatchesSnapshotTest();
122122

123123
$mockTrait->assertMatchesJsonSnapshot('{"foo":"baz","bar":"baz","baz":"foo"}');
124124
}
@@ -174,17 +174,26 @@ public function it_can_update_a_json_snapshot()
174174
);
175175
}
176176

177-
protected function expectIncompleteMatchesSnapshotTest(PHPUnit_Framework_MockObject_MockObject $matchesSnapshotMock)
177+
private function expectIncompleteMatchesSnapshotTest(PHPUnit_Framework_MockObject_MockObject $matchesSnapshotMock)
178178
{
179179
$matchesSnapshotMock
180180
->expects($this->once())
181181
->method('markTestIncomplete');
182182
}
183183

184+
private function expectFailedMatchesSnapshotTest()
185+
{
186+
if (class_exists('PHPUnit\Framework\ExpectationFailedException')) {
187+
$this->expectException('PHPUnit\Framework\ExpectationFailedException');
188+
} else {
189+
$this->expectException('PHPUnit_Framework_ExpectationFailedException');
190+
}
191+
}
192+
184193
/**
185194
* @return \PHPUnit_Framework_MockObject_MockObject
186195
*/
187-
protected function getMatchesSnapshotMock(): PHPUnit_Framework_MockObject_MockObject
196+
private function getMatchesSnapshotMock(): PHPUnit_Framework_MockObject_MockObject
188197
{
189198
$mockMethods = [
190199
'markTestIncomplete',

0 commit comments

Comments
 (0)