Skip to content

Commit f654eba

Browse files
committed
add html driver integration tests and fix existing
1 parent 5893d24 commit f654eba

8 files changed

+89
-1
lines changed

tests/Integration/AssertionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ public function can_match_a_string_snapshot()
2525
$this->assertMatchesSnapshot($data);
2626
}
2727

28+
/** @test */
29+
public function can_match_an_html_snapshot()
30+
{
31+
$data = '<!doctype html><html lang="en"><head></head><body><h1>Hello, world!</h1></body></html>';
32+
33+
$this->assertMatchesHtmlSnapshot($data);
34+
}
35+
2836
/** @test */
2937
public function can_match_an_xml_snapshot()
3038
{

tests/Integration/MatchesSnapshotTest.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ public function it_can_create_a_snapshot_from_an_array()
5454
);
5555
}
5656

57+
/** @test */
58+
public function it_can_create_a_snapshot_from_html()
59+
{
60+
$mockTrait = $this->getMatchesSnapshotMock();
61+
62+
$this->expectIncompleteMatchesSnapshotTest($mockTrait, function ($mockTrait) {
63+
$mockTrait->assertMatchesHtmlSnapshot('<!doctype html><html lang="en"><head></head><body><h1>Hello, world!</h1></body></html>');
64+
});
65+
66+
$this->assertSnapshotMatchesExample(
67+
'MatchesSnapshotTest__it_can_create_a_snapshot_from_html__1.html',
68+
'snapshot.html'
69+
);
70+
}
71+
5772
/** @test */
5873
public function it_can_create_a_snapshot_from_xml()
5974
{
@@ -107,6 +122,14 @@ public function it_can_match_an_existing_string_snapshot()
107122
$mockTrait->assertMatchesSnapshot('Foo');
108123
}
109124

125+
/** @test */
126+
public function it_can_match_an_existing_html_snapshot()
127+
{
128+
$mockTrait = $this->getMatchesSnapshotMock();
129+
130+
$mockTrait->assertMatchesHtmlSnapshot('<!doctype html><html lang="en"><head></head><body><h1>Hello, world!</h1></body></html>');
131+
}
132+
110133
/** @test */
111134
public function it_can_match_an_existing_xml_snapshot()
112135
{
@@ -141,6 +164,16 @@ public function it_can_mismatch_a_string_snapshot()
141164
$mockTrait->assertMatchesSnapshot('Bar');
142165
}
143166

167+
/** @test */
168+
public function it_can_mismatch_a_html_snapshot()
169+
{
170+
$mockTrait = $this->getMatchesSnapshotMock();
171+
172+
$this->expectFailedMatchesSnapshotTest();
173+
174+
$mockTrait->assertMatchesHtmlSnapshot('<!doctype html><html lang="en"><head></head><body><h1>Hallo welt!</h1></body></html>');
175+
}
176+
144177
/** @test */
145178
public function it_can_mismatch_a_xml_snapshot()
146179
{
@@ -257,6 +290,23 @@ public function it_can_update_a_string_snapshot()
257290
);
258291
}
259292

293+
/** @test */
294+
public function it_can_update_a_html_snapshot()
295+
{
296+
$_SERVER['argv'][] = '--update-snapshots';
297+
298+
$mockTrait = $this->getMatchesSnapshotMock();
299+
300+
$this->expectIncompleteMatchesSnapshotTest($mockTrait, function ($mockTrait) {
301+
$mockTrait->assertMatchesHtmlSnapshot('<!doctype html><html lang="en"><head></head><body><h1>Hello, world!</h1></body></html>');
302+
});
303+
304+
$this->assertSnapshotMatchesExample(
305+
'MatchesSnapshotTest__it_can_update_a_html_snapshot__1.html',
306+
'snapshot.html'
307+
);
308+
}
309+
260310
/** @test */
261311
public function it_can_update_a_xml_snapshot()
262312
{
@@ -355,7 +405,7 @@ private function expectFailedMatchesSnapshotTest()
355405
}
356406

357407
/**
358-
* @return \PHPUnit\Framework\MockObject\MockObject
408+
* @return \PHPUnit\Framework\MockObject\MockObject|\Spatie\Snapshots\MatchesSnapshots
359409
*/
360410
private function getMatchesSnapshotMock(): MockObject
361411
{
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"foo": "foo",
3+
"bar": "bar",
4+
"baz": "baz"
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head></head>
4+
<body><h1>Hello, world!</h1></body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head></head>
4+
<body><h1>Hello, world!</h1></body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head></head>
4+
<body><h1>Hello, world!</h1></body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head></head>
4+
<body><h1>Hallo welt!</h1></body>
5+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head></head>
4+
<body><h1>Hello, world!</h1></body>
5+
</html>

0 commit comments

Comments
 (0)