From e46d499384a5404601b172ec509d079daae471bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Birkl=C3=A9?= Date: Wed, 19 Mar 2025 16:33:44 +0100 Subject: [PATCH] add tests for snapshots external to the tests directory --- phpunit.xml | 1 + .../Features/Expect/toMatchSnapshot.php | 35 +++++++++++++++++++ ...tas_set_value______my_datas_set_value__.snap | 7 ++++ ...s_set_value______my_datas_set_value__.snap | 7 ++++ tests/Features/Expect/toMatchSnapshot.php | 6 ++-- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 tests-external/Features/Expect/toMatchSnapshot.php create mode 100644 tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/_within_describe__→_pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap create mode 100644 tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap diff --git a/phpunit.xml b/phpunit.xml index 4aac1aa2..122f54e2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -16,6 +16,7 @@ ./tests + ./tests-external ./tests/.snapshots ./tests/.tests ./tests/Fixtures/Inheritance diff --git a/tests-external/Features/Expect/toMatchSnapshot.php b/tests-external/Features/Expect/toMatchSnapshot.php new file mode 100644 index 00000000..db7b9666 --- /dev/null +++ b/tests-external/Features/Expect/toMatchSnapshot.php @@ -0,0 +1,35 @@ +snapshotable = <<<'HTML' +
+
+
+

Snapshot

+
+
+
+ HTML; +}); + +test('pass with dataset', function ($data) { + TestSuite::getInstance()->snapshots->save($this->snapshotable); + [$filename] = TestSuite::getInstance()->snapshots->get(); + + expect($filename)->toStartWith('tests/.pest/snapshots-external/') + ->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap') + ->and($this->snapshotable)->toMatchSnapshot(); +})->with(['my-datas-set-value']); + +describe('within describe', function () { + test('pass with dataset', function ($data) { + TestSuite::getInstance()->snapshots->save($this->snapshotable); + [$filename] = TestSuite::getInstance()->snapshots->get(); + + expect($filename)->toStartWith('tests/.pest/snapshots-external/') + ->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap') + ->and($this->snapshotable)->toMatchSnapshot(); + }); +})->with(['my-datas-set-value']); \ No newline at end of file diff --git a/tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/_within_describe__→_pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap b/tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/_within_describe__→_pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap new file mode 100644 index 00000000..c2b4dc0a --- /dev/null +++ b/tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/_within_describe__→_pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap @@ -0,0 +1,7 @@ +
+
+
+

Snapshot

+
+
+
\ No newline at end of file diff --git a/tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap b/tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap new file mode 100644 index 00000000..c2b4dc0a --- /dev/null +++ b/tests/.pest/snapshots-external/Features/Expect/toMatchSnapshot/pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap @@ -0,0 +1,7 @@ +
+
+
+

Snapshot

+
+
+
\ No newline at end of file diff --git a/tests/Features/Expect/toMatchSnapshot.php b/tests/Features/Expect/toMatchSnapshot.php index c3df8bac..c2515829 100644 --- a/tests/Features/Expect/toMatchSnapshot.php +++ b/tests/Features/Expect/toMatchSnapshot.php @@ -74,7 +74,8 @@ test('pass with dataset', function ($data) { TestSuite::getInstance()->snapshots->save($this->snapshotable); [$filename] = TestSuite::getInstance()->snapshots->get(); - expect($filename)->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap') + expect($filename)->toStartWith('tests/.pest/snapshots/') + ->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap') ->and($this->snapshotable)->toMatchSnapshot(); })->with(['my-datas-set-value']); @@ -83,7 +84,8 @@ describe('within describe', function () { TestSuite::getInstance()->snapshots->save($this->snapshotable); [$filename] = TestSuite::getInstance()->snapshots->get(); - expect($filename)->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap') + expect($filename)->toStartWith('tests/.pest/snapshots/') + ->toEndWith('pass_with_dataset_with_data_set____my_datas_set_value______my_datas_set_value__.snap') ->and($this->snapshotable)->toMatchSnapshot(); }); })->with(['my-datas-set-value']);