Skip to content

Commit a96bfb9

Browse files
committed
Tests for explicit IDs
1 parent f16cbcd commit a96bfb9

File tree

19 files changed

+113
-0
lines changed

19 files changed

+113
-0
lines changed

tests/Integration/AssertionTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,97 @@ public function can_do_multiple_snapshot_assertions()
8080
$this->assertMatchesSnapshot('Foo');
8181
$this->assertMatchesSnapshot('Bar');
8282
}
83+
84+
#[Test]
85+
public function can_match_a_snapshot_with_explicit_id()
86+
{
87+
$this->assertMatchesSnapshot('Foo', null, 'my-snapshot');
88+
}
89+
90+
#[Test]
91+
public function can_match_a_json_snapshot_with_explicit_id()
92+
{
93+
$this->assertMatchesJsonSnapshot('{"foo":"bar"}', 'my-json-snapshot');
94+
}
95+
96+
#[Test]
97+
public function can_match_an_html_snapshot_with_explicit_id()
98+
{
99+
$this->assertMatchesHtmlSnapshot('<html><body>Hello</body></html>', 'my-html-snapshot');
100+
}
101+
102+
#[Test]
103+
public function can_match_an_xml_snapshot_with_explicit_id()
104+
{
105+
$this->assertMatchesXmlSnapshot('<root><item>Test</item></root>', 'my-xml-snapshot');
106+
}
107+
108+
#[Test]
109+
public function can_match_a_text_snapshot_with_explicit_id()
110+
{
111+
$this->assertMatchesTextSnapshot('Hello World', 'my-text-snapshot');
112+
}
113+
114+
#[Test]
115+
public function can_match_an_object_snapshot_with_explicit_id()
116+
{
117+
$this->assertMatchesObjectSnapshot(['key' => 'value'], 'my-object-snapshot');
118+
}
119+
120+
#[Test]
121+
public function can_match_a_yaml_snapshot_with_explicit_id()
122+
{
123+
$this->assertMatchesYamlSnapshot(['name' => 'test'], 'my-yaml-snapshot');
124+
}
125+
126+
#[Test]
127+
public function can_match_a_file_hash_snapshot_with_explicit_id()
128+
{
129+
$filePath = __DIR__.'/stubs/example_snapshots/snapshot.json';
130+
131+
$this->assertMatchesFileHashSnapshot($filePath, 'my-file-hash-snapshot');
132+
}
133+
134+
#[Test]
135+
public function can_match_a_file_snapshot_with_explicit_id()
136+
{
137+
$filePath = __DIR__.'/stubs/test_files/friendly_man.jpg';
138+
139+
$this->assertMatchesFileSnapshot($filePath, 'my-file-snapshot');
140+
}
141+
142+
#[Test]
143+
public function explicit_ids_do_not_affect_auto_increment_ids()
144+
{
145+
// First auto-increment: __1
146+
$this->assertMatchesSnapshot('First');
147+
148+
// Explicit ID: __s-named
149+
$this->assertMatchesSnapshot('Named', null, 'named');
150+
151+
// Second auto-increment should be __2, not __3
152+
$this->assertMatchesSnapshot('Second');
153+
154+
// Another explicit ID
155+
$this->assertMatchesSnapshot('AnotherNamed', null, 'another-named');
156+
157+
// Third auto-increment should be __3
158+
$this->assertMatchesSnapshot('Third');
159+
}
160+
161+
#[Test]
162+
public function numeric_explicit_ids_do_not_conflict_with_auto_increment_ids()
163+
{
164+
// Explicit ID with numeric value that could conflict: __s-1
165+
$this->assertMatchesSnapshot('ExplicitOne', null, '1');
166+
167+
// Auto-increment: __1 (should not conflict with __s-1)
168+
$this->assertMatchesSnapshot('AutoOne');
169+
170+
// Another explicit numeric ID: __s-2
171+
$this->assertMatchesSnapshot('ExplicitTwo', null, '2');
172+
173+
// Auto-increment: __2 (should not conflict with __s-2)
174+
$this->assertMatchesSnapshot('AutoTwo');
175+
}
83176
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f558f8149e33fba2916877b2d3de4a42ebd544b4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"foo":"bar"}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Foo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<html><body>Hello</body></html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
key: value
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0"?>
2+
<root>
3+
<item>Test</item>
4+
</root>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
First

0 commit comments

Comments
 (0)