Skip to content

Commit

Permalink
docs and collection snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Nov 22, 2023
1 parent 8964789 commit 985164c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/test/SnapshotAssertions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
* it('matches dom lists')->get('/')->querySelector('h1')->assertMatchesSnapshot();
* it('matches views')->renderTemplate('_news/entry', $variables)->assertMatchesSnapshot();
* ```
*
* ## Elements
*
* Many elements can be snapshotted as well. Unfortunately, Pest is not smart enough to properly
* snapshot elements so you must call `->toSnapshot()` on them first.
*
* ```php
* it('imports entries', function () {
* $this->importEntries();
* $entries = Entry::find()->section('news')->collect();
*
* expect($entries->map->toSnapshot())->toMatchSnapshot();
* });
* ```
*/
trait SnapshotAssertions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"expiryDate":null,"deletedWithEntryType":false,"_authorId":null,"tempId":null,"draftId":null,"revisionId":null,"isProvisionalDraft":false,"enabled":true,"archived":false,"siteId":2,"title":"Entry 0","slug":"entry-0","uri":"posts\/entry-0","dateLastMerged":null,"dateDeleted":null,"trashed":false,"isNewForSite":false,"isDraft":false,"isRevision":false,"isUnpublishedDraft":false,"ref":"posts\/entry-0","status":"live","structureId":null,"url":"http:\/\/localhost:8080\/index.php?p=posts\/entry-0","authorId":null},{"expiryDate":null,"deletedWithEntryType":false,"_authorId":null,"tempId":null,"draftId":null,"revisionId":null,"isProvisionalDraft":false,"enabled":true,"archived":false,"siteId":2,"title":"Entry 1","slug":"entry-1","uri":"posts\/entry-1","dateLastMerged":null,"dateDeleted":null,"trashed":false,"isNewForSite":false,"isDraft":false,"isRevision":false,"isUnpublishedDraft":false,"ref":"posts\/entry-1","status":"live","structureId":null,"url":"http:\/\/localhost:8080\/index.php?p=posts\/entry-1","authorId":null},{"expiryDate":null,"deletedWithEntryType":false,"_authorId":null,"tempId":null,"draftId":null,"revisionId":null,"isProvisionalDraft":false,"enabled":true,"archived":false,"siteId":2,"title":"Entry 2","slug":"entry-2","uri":"posts\/entry-2","dateLastMerged":null,"dateDeleted":null,"trashed":false,"isNewForSite":false,"isDraft":false,"isRevision":false,"isUnpublishedDraft":false,"ref":"posts\/entry-2","status":"live","structureId":null,"url":"http:\/\/localhost:8080\/index.php?p=posts\/entry-2","authorId":null}]
7 changes: 7 additions & 0 deletions tests/SnapshotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,10 @@

expect($entry)->toMatchElementSnapshot();
});

it('matches collected snapshots', function () {
Entry::factory()->section('posts')->count(3)->sequence(fn ($index) => ['title' => 'Entry '.$index])->create();
$entries = \craft\elements\Entry::find()->section('posts')->collect();

expect($entries->map->toSnapshot())->toMatchSnapshot();
});

0 comments on commit 985164c

Please sign in to comment.