diff --git a/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshot_assertions.snap b/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshot_assertions.snap index bbcf481..9dc4c50 100644 --- a/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshot_assertions.snap +++ b/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshot_assertions.snap @@ -3,7 +3,7 @@ "slug": "foo-bar", "isDraft": false, "isRevision": false, - "isNewForSite": true, + "isNewForSite": false, "isUnpublishedDraft": false, "enabled": true, "archived": false, diff --git a/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshots.snap b/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshots.snap index bbcf481..9dc4c50 100644 --- a/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshots.snap +++ b/tests/.pest/snapshots/SnapshotTest/it_includes_postDate_in_snapshots.snap @@ -3,7 +3,7 @@ "slug": "foo-bar", "isDraft": false, "isRevision": false, - "isNewForSite": true, + "isNewForSite": false, "isUnpublishedDraft": false, "enabled": true, "archived": false, diff --git a/tests/.pest/snapshots/SnapshotTest/it_matches_entry_snapshots.snap b/tests/.pest/snapshots/SnapshotTest/it_matches_entry_snapshots.snap index 4a730f4..d76066d 100644 --- a/tests/.pest/snapshots/SnapshotTest/it_matches_entry_snapshots.snap +++ b/tests/.pest/snapshots/SnapshotTest/it_matches_entry_snapshots.snap @@ -3,7 +3,7 @@ "slug": "foo-bar", "isDraft": false, "isRevision": false, - "isNewForSite": true, + "isNewForSite": false, "isUnpublishedDraft": false, "enabled": true, "archived": false, diff --git a/tests/SnapshotTest.php b/tests/SnapshotTest.php index a5279b1..dde23e3 100644 --- a/tests/SnapshotTest.php +++ b/tests/SnapshotTest.php @@ -39,35 +39,6 @@ ->renderTemplate('variable', ['foo' => 'bar']) ->assertMatchesSnapshot(); -it('includes postDate in snapshots') - ->expect(fn () => Entry::factory() - ->section('posts') - ->postDate('2022-01-01 00:00:00') - ->title('foo bar') - ->create()) - ->toSnapshot(['postDate'])->toMatchSnapshot(); - -it('includes postDate in snapshot assertions', function () { - $entry = Entry::factory() - ->section('posts') - ->postDate('2022-01-01 00:00:00') - ->title('foo bar') - ->create(); - - $entry->assertMatchesSnapshot(['postDate']); -}); - -it('matches entry snapshots', function () { - $entry = Entry::factory() - ->section('posts') - ->title('foo bar') - ->textField('foo') - ->dropdownField('one') - ->create(); - - expect($entry)->toMatchSnapshot(); -}); - it('matches nested entry snapshots', function () { $child = Entry::factory() ->section('posts') @@ -91,3 +62,43 @@ $snapshots = collect($entries->map->toSnapshotArray())->sortBy('title')->values()->all(); expect(json_encode($snapshots))->toMatchSnapshot(); }); + +// Before 5.3.3 Craft reported isNewForSite as `true` after a save but thanks to +// https://github.com/craftcms/cms/issues/15517 it switched to `false. So, to avoid splitting our +// tests we don't actually check snapshots on newly created elements. We re-fetch them from +// the database to be sure we're not running in to differences with isNewForSite between +// Craft versions +it('includes postDate in snapshots', function () { + $entry = Entry::factory() + ->section('posts') + ->postDate('2022-01-01 00:00:00') + ->title('foo bar') + ->create(); + + expect(\craft\elements\Entry::find()->id($entry->id)->one()) + ->toSnapshot(['postDate']) + ->toMatchSnapshot(); +}); + +it('includes postDate in snapshot assertions', function () { + $entry = Entry::factory() + ->section('posts') + ->postDate('2022-01-01 00:00:00') + ->title('foo bar') + ->create(); + + expect(\craft\elements\Entry::find()->id($entry->id)->one()) + ->assertMatchesSnapshot(['postDate']); +}); + +it('matches entry snapshots', function () { + $entry = Entry::factory() + ->section('posts') + ->title('foo bar') + ->textField('foo') + ->dropdownField('one') + ->create(); + + expect(\craft\elements\Entry::find()->id($entry->id)->one()) + ->toMatchSnapshot(); +});