Skip to content

Commit f05fe6a

Browse files
authored
Merge pull request #288 from fkupper/patch-3
Add extra snapshot file format documentation
2 parents 1a5ef8b + a4c2626 commit f05fe6a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/09-Data.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,33 @@ public function testCategoriesAreTheSame(\AcceptanceTester $I, \Snapshot\Categor
384384
}
385385

386386
{% endhighlight %}
387-
387+
388388
If ever needed, the diff output can also be omitted by calling `shouldShowDiffOnFail(false)`.
389389

390+
### Working with different data formats
391+
392+
By default, all snapshot files are stored in json format, so if you have to work with different formats, neither the diff output or the snapshot file data will be helpful.
393+
To fix this, you can call the snapshot method `shouldSaveAsJson(false)` and set the file extension by calling `setSnapshotFileExtension()`:
394+
395+
{% highlight php %}
396+
397+
<?php
398+
public function testCategoriesAreTheSame(\AcceptanceTester $I, \Snapshot\Categories $snapshot)
399+
{
400+
// I fetch an HTML page
401+
$I->amOnPage('/categories.html');
402+
// I want to see the diff in case the snapshot data changes
403+
$snapshot->shouldSaveAsJson(false);
404+
$snapshot->setSnapshotFileExtension('html');
405+
$snapshot->assert();
406+
}
407+
408+
{% endhighlight %}
409+
410+
The snapshot file will be stored without encoding it to json format, and with the `.html` extension.
411+
412+
> Beware that this option will not perform any changes in the data returned by `fetchData`, and store it as it is.
413+
390414
## Conclusion
391415

392416
Codeception also assists the developer when dealing with data. Tools for database population

0 commit comments

Comments
 (0)