From 2d4c0367080cfcdba7345b58dc4bb54896cccd03 Mon Sep 17 00:00:00 2001 From: simonhammes Date: Sun, 18 Feb 2024 12:55:34 +0100 Subject: [PATCH] Use PHPUnit attributes Fixes #186 --- src/MatchesSnapshots.php | 6 +- tests/Integration/AssertionTest.php | 17 +++--- tests/Integration/MatchesSnapshotTest.php | 67 ++++++++++++----------- tests/Unit/Drivers/HtmlDriverTest.php | 11 ++-- tests/Unit/Drivers/ImageDriverTest.php | 9 +-- tests/Unit/Drivers/JsonDriverTest.php | 38 ++++++------- tests/Unit/Drivers/ObjectDriverTest.php | 15 ++--- tests/Unit/Drivers/TextDriverTest.php | 5 +- tests/Unit/Drivers/XmlDriverTest.php | 5 +- tests/Unit/Drivers/YamlDriverTest.php | 5 +- tests/Unit/FilenameTest.php | 9 ++- tests/Unit/SnapshotTest.php | 7 ++- 12 files changed, 102 insertions(+), 92 deletions(-) diff --git a/src/MatchesSnapshots.php b/src/MatchesSnapshots.php index 8d68f53..9efc654 100644 --- a/src/MatchesSnapshots.php +++ b/src/MatchesSnapshots.php @@ -2,6 +2,8 @@ namespace Spatie\Snapshots; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\PostCondition; use PHPUnit\Framework\ExpectationFailedException; use ReflectionObject; use Spatie\Snapshots\Concerns\SnapshotDirectoryAware; @@ -23,13 +25,13 @@ trait MatchesSnapshots protected array $snapshotChanges = []; - /** @before */ + #[Before] public function setUpSnapshotIncrementor() { $this->snapshotIncrementor = 0; } - /** @postCondition */ + #[PostCondition] public function markTestIncompleteIfSnapshotsHaveChanged() { if (empty($this->snapshotChanges)) { diff --git a/tests/Integration/AssertionTest.php b/tests/Integration/AssertionTest.php index b625555..533b438 100644 --- a/tests/Integration/AssertionTest.php +++ b/tests/Integration/AssertionTest.php @@ -2,6 +2,7 @@ namespace Spatie\Snapshots\Test\Integration; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\MatchesSnapshots; @@ -17,7 +18,7 @@ public function setUp(): void $this->setUpComparesSnapshotFiles(); } - /** @test */ + #[Test] public function can_match_a_string_snapshot() { $data = 'Foo'; @@ -25,7 +26,7 @@ public function can_match_a_string_snapshot() $this->assertMatchesSnapshot($data); } - /** @test */ + #[Test] public function can_match_an_html_snapshot() { $data = '

Hello, world!

'; @@ -33,7 +34,7 @@ public function can_match_an_html_snapshot() $this->assertMatchesHtmlSnapshot($data); } - /** @test */ + #[Test] public function can_match_an_xml_snapshot() { $data = 'Baz'; @@ -41,7 +42,7 @@ public function can_match_an_xml_snapshot() $this->assertMatchesXmlSnapshot($data); } - /** @test */ + #[Test] public function can_match_a_json_snapshot() { $data = '{"foo":"foo","bar":"bar","baz":"baz"}'; @@ -49,7 +50,7 @@ public function can_match_a_json_snapshot() $this->assertMatchesJsonSnapshot($data); } - /** @test */ + #[Test] public function can_match_an_array_snapshot() { $data = ['foo' => 'foo', 'bar' => 'bar', 'baz' => 'baz']; @@ -57,7 +58,7 @@ public function can_match_an_array_snapshot() $this->assertMatchesJsonSnapshot($data); } - /** @test */ + #[Test] public function can_match_a_file_hash_snapshot() { $filePath = __DIR__.'/stubs/example_snapshots/snapshot.json'; @@ -65,7 +66,7 @@ public function can_match_a_file_hash_snapshot() $this->assertMatchesFileHashSnapshot($filePath); } - /** @test */ + #[Test] public function can_match_a_file_snapshot() { $filePath = __DIR__.'/stubs/test_files/friendly_man.jpg'; @@ -73,7 +74,7 @@ public function can_match_a_file_snapshot() $this->assertMatchesFileSnapshot($filePath); } - /** @test */ + #[Test] public function can_do_multiple_snapshot_assertions() { $this->assertMatchesSnapshot('Foo'); diff --git a/tests/Integration/MatchesSnapshotTest.php b/tests/Integration/MatchesSnapshotTest.php index 17a60f7..7d86997 100644 --- a/tests/Integration/MatchesSnapshotTest.php +++ b/tests/Integration/MatchesSnapshotTest.php @@ -3,6 +3,7 @@ namespace Spatie\Snapshots\Test\Integration; use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -30,7 +31,7 @@ public function setUp(): void } } - /** @test */ + #[Test] public function it_can_create_a_snapshot_from_a_string() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -45,7 +46,7 @@ public function it_can_create_a_snapshot_from_a_string() ); } - /** @test */ + #[Test] public function it_can_create_a_snapshot_from_an_array() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -60,7 +61,7 @@ public function it_can_create_a_snapshot_from_an_array() ); } - /** @test */ + #[Test] public function it_can_create_a_snapshot_from_html() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -75,7 +76,7 @@ public function it_can_create_a_snapshot_from_html() ); } - /** @test */ + #[Test] public function it_can_create_a_snapshot_from_xml() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -90,7 +91,7 @@ public function it_can_create_a_snapshot_from_xml() ); } - /** @test */ + #[Test] public function it_can_create_a_snapshot_from_json() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -105,7 +106,7 @@ public function it_can_create_a_snapshot_from_json() ); } - /** @test */ + #[Test] public function it_can_create_a_snapshot_from_a_file() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -120,7 +121,7 @@ public function it_can_create_a_snapshot_from_a_file() ); } - /** @test */ + #[Test] public function it_can_match_an_existing_string_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -128,7 +129,7 @@ public function it_can_match_an_existing_string_snapshot() $mockTrait->assertMatchesSnapshot('Foo'); } - /** @test */ + #[Test] public function it_can_match_an_existing_html_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -136,7 +137,7 @@ public function it_can_match_an_existing_html_snapshot() $mockTrait->assertMatchesHtmlSnapshot('

Hello, world!

'); } - /** @test */ + #[Test] public function it_can_match_an_existing_xml_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -144,7 +145,7 @@ public function it_can_match_an_existing_xml_snapshot() $mockTrait->assertMatchesXmlSnapshot('Baz'); } - /** @test */ + #[Test] public function it_can_match_an_existing_json_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -152,7 +153,7 @@ public function it_can_match_an_existing_json_snapshot() $mockTrait->assertMatchesJsonSnapshot('{"foo":"foo","bar":"bar","baz":"baz"}'); } - /** @test */ + #[Test] public function it_can_match_an_existing_file_hash_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -160,7 +161,7 @@ public function it_can_match_an_existing_file_hash_snapshot() $mockTrait->assertMatchesFileHashSnapshot(__DIR__.'/stubs/example_snapshots/snapshot.json'); } - /** @test */ + #[Test] public function it_can_mismatch_a_string_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -170,7 +171,7 @@ public function it_can_mismatch_a_string_snapshot() $mockTrait->assertMatchesSnapshot('Bar'); } - /** @test */ + #[Test] public function it_can_mismatch_a_html_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -180,7 +181,7 @@ public function it_can_mismatch_a_html_snapshot() $mockTrait->assertMatchesHtmlSnapshot('

Hallo welt!

'); } - /** @test */ + #[Test] public function it_can_mismatch_a_xml_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -190,7 +191,7 @@ public function it_can_mismatch_a_xml_snapshot() $mockTrait->assertMatchesXmlSnapshot('Foo'); } - /** @test */ + #[Test] public function it_can_mismatch_a_json_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -200,7 +201,7 @@ public function it_can_mismatch_a_json_snapshot() $mockTrait->assertMatchesJsonSnapshot('{"foo":"baz","bar":"baz","baz":"foo"}'); } - /** @test */ + #[Test] public function it_can_mismatch_a_file_hash_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -210,7 +211,7 @@ public function it_can_mismatch_a_file_hash_snapshot() $mockTrait->assertMatchesFileHashSnapshot(__DIR__.'/stubs/example_snapshots/snapshot.json'); } - /** @test */ + #[Test] public function it_can_mismatch_a_file_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -223,7 +224,7 @@ public function it_can_mismatch_a_file_snapshot() $mockTrait->assertMatchesFileSnapshot(__DIR__.'/stubs/test_files/troubled_man.jpg'); } - /** @test */ + #[Test] public function it_can_mismatch_a_file_snapshot_with_a_different_extension() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -236,7 +237,7 @@ public function it_can_mismatch_a_file_snapshot_with_a_different_extension() $mockTrait->assertMatchesFileSnapshot(__DIR__.'/stubs/test_files/no_man.png'); } - /** @test */ + #[Test] public function it_needs_a_file_extension_to_do_a_file_snapshot_assertion() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -254,7 +255,7 @@ public function it_needs_a_file_extension_to_do_a_file_snapshot_assertion() $mockTrait->assertMatchesFileSnapshot($filePath); } - /** @test */ + #[Test] public function it_persists_the_failed_file_after_mismatching_a_file_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -274,7 +275,7 @@ public function it_persists_the_failed_file_after_mismatching_a_file_snapshot() $this->assertFileEquals($mismatchedFile, $persistedFailedFile); } - /** @test */ + #[Test] public function it_deletes_the_persisted_failed_file_before_a_file_snapshot_assertion() { $mockTrait = $this->getMatchesSnapshotMock(); @@ -292,7 +293,7 @@ public function it_deletes_the_persisted_failed_file_before_a_file_snapshot_asse $this->assertFileDoesNotExist($persistedFailedFile); } - /** @test */ + #[Test] public function it_cleans_filenames_on_file_snapshot() { $mockTrait = $this->getMatchesSnapshotMock(false); @@ -309,7 +310,7 @@ public function it_cleans_filenames_on_file_snapshot() $mockTrait->assertMatchesFileSnapshot(__DIR__.'/stubs/test_files/troubled_man.jpg'); } - /** @test */ + #[Test] public function it_can_update_a_string_snapshot() { $_SERVER['argv'][] = '--update-snapshots'; @@ -326,7 +327,7 @@ public function it_can_update_a_string_snapshot() ); } - /** @test */ + #[Test] public function it_can_update_a_html_snapshot() { $_SERVER['argv'][] = '--update-snapshots'; @@ -343,7 +344,7 @@ public function it_can_update_a_html_snapshot() ); } - /** @test */ + #[Test] public function it_can_update_a_xml_snapshot() { $_SERVER['argv'][] = '--update-snapshots'; @@ -360,7 +361,7 @@ public function it_can_update_a_xml_snapshot() ); } - /** @test */ + #[Test] public function it_can_update_a_json_snapshot() { $_SERVER['argv'][] = '--update-snapshots'; @@ -377,7 +378,7 @@ public function it_can_update_a_json_snapshot() ); } - /** @test */ + #[Test] public function it_can_update_a_file_snapshot() { $_SERVER['argv'][] = '--update-snapshots'; @@ -394,7 +395,7 @@ public function it_can_update_a_file_snapshot() ); } - /** @test */ + #[Test] public function it_can_update_a_file_snapshot_with_a_different_extension() { $_SERVER['argv'][] = '--update-snapshots'; @@ -417,7 +418,7 @@ public function it_can_update_a_file_snapshot_with_a_different_extension() $this->assertFileDoesNotExist($oldSnapshot); } - /** @test */ + #[Test] public function it_can_update_a_snapshot_with_env_var() { putenv('UPDATE_SNAPSHOTS=true'); @@ -505,7 +506,7 @@ private function getMatchesSnapshotMock(bool $mockGetSnapshotId = true): MockObj return $matchesSnapshotMock; } - /** @test */ + #[Test] public function it_doesnt_create_a_regular_snapshot_and_mismatches_if_asked() { $_SERVER['argv'][] = '--without-creating-snapshots'; @@ -521,7 +522,7 @@ public function it_doesnt_create_a_regular_snapshot_and_mismatches_if_asked() $mockTrait->assertMatchesSnapshot('Bar'); } - /** @test */ + #[Test] public function it_doesnt_create_a_file_snapshot_and_mismatches_if_asked() { $_SERVER['argv'][] = '--without-creating-snapshots'; @@ -537,7 +538,7 @@ public function it_doesnt_create_a_file_snapshot_and_mismatches_if_asked() $mockTrait->assertMatchesFileSnapshot(__DIR__.'/stubs/test_files/friendly_man.jpg'); } - /** @test */ + #[Test] public function it_doesnt_create_a_regular_snapshot_and_mismatches_if_asked_with_env_var() { putenv('CREATE_SNAPSHOTS=false'); @@ -553,7 +554,7 @@ public function it_doesnt_create_a_regular_snapshot_and_mismatches_if_asked_with $mockTrait->assertMatchesSnapshot('Bar'); } - /** @test */ + #[Test] public function it_doesnt_create_a_file_snapshot_and_mismatches_if_asked_with_env_var() { putenv('CREATE_SNAPSHOTS=false'); diff --git a/tests/Unit/Drivers/HtmlDriverTest.php b/tests/Unit/Drivers/HtmlDriverTest.php index 4b315ba..cdfcbec 100644 --- a/tests/Unit/Drivers/HtmlDriverTest.php +++ b/tests/Unit/Drivers/HtmlDriverTest.php @@ -2,13 +2,14 @@ namespace Spatie\Snapshots\Test\Unit\Drivers; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Drivers\HtmlDriver; use Spatie\Snapshots\Exceptions\CantBeSerialized; class HtmlDriverTest extends TestCase { - /** @test */ + #[Test] public function it_can_serialize_a_html_string_to_pretty_html() { $driver = new HtmlDriver(); @@ -25,7 +26,7 @@ public function it_can_serialize_a_html_string_to_pretty_html() $this->assertEquals($expected, $driver->serialize('

Hello, world!

')); } - /** @test */ + #[Test] public function test_for_issue_140() { $driver = new HtmlDriver(); @@ -46,7 +47,7 @@ public function test_for_issue_140() $this->assertEquals($expected, $driver->serialize($expected)); } - /** @test */ + #[Test] public function it_can_serialize_a_html_string_without_a_doctype() { $driver = new HtmlDriver(); @@ -62,7 +63,7 @@ public function it_can_serialize_a_html_string_without_a_doctype() $this->assertEquals($expected, $driver->serialize('

Hello, world!

')); } - /** @test */ + #[Test] public function it_can_only_serialize_strings() { $driver = new HtmlDriver(); @@ -72,7 +73,7 @@ public function it_can_only_serialize_strings() $driver->serialize(['foo' => 'bar']); } - /** @test */ + #[Test] public function it_can_serialize_an_empty_string() { $driver = new HtmlDriver(); diff --git a/tests/Unit/Drivers/ImageDriverTest.php b/tests/Unit/Drivers/ImageDriverTest.php index 12806f7..8b16acd 100644 --- a/tests/Unit/Drivers/ImageDriverTest.php +++ b/tests/Unit/Drivers/ImageDriverTest.php @@ -2,6 +2,7 @@ namespace Spatie\Snapshots\Test\Unit\Drivers; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Drivers\ImageDriver; @@ -20,7 +21,7 @@ public function setUp(): void } - /** @test */ + #[Test] public function it_can_serialize_an_image() { $data = $this->driver->serialize($this->pathToImageA); @@ -28,7 +29,7 @@ public function it_can_serialize_an_image() $this->assertEquals($data, file_get_contents($this->pathToImageA)); } - /** @test */ + #[Test] public function it_can_determine_that_two_images_are_the_same() { $this->driver->match( @@ -39,7 +40,7 @@ public function it_can_determine_that_two_images_are_the_same() $this->doesNotPerformAssertions(); } - /** @test */ + #[Test] public function it_can_determine_that_two_images_are_not_same() { $this->expectException(ExpectationFailedException::class); @@ -50,7 +51,7 @@ public function it_can_determine_that_two_images_are_not_same() ); } - /** @test */ + #[Test] public function it_will_determine_that_two_images_with_different_dimensions_are_different() { $this->expectException(ExpectationFailedException::class); diff --git a/tests/Unit/Drivers/JsonDriverTest.php b/tests/Unit/Drivers/JsonDriverTest.php index 10b9a43..28d2635 100644 --- a/tests/Unit/Drivers/JsonDriverTest.php +++ b/tests/Unit/Drivers/JsonDriverTest.php @@ -2,6 +2,9 @@ namespace Spatie\Snapshots\Test\Unit\Drivers; +use PHPUnit\Framework\Attributes\Test; +use PHPUnit\Framework\Attributes\TestWith; +use PHPUnit\Framework\Attributes\TestWithJson; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Drivers\JsonDriver; @@ -9,7 +12,7 @@ class JsonDriverTest extends TestCase { - /** @test */ + #[Test] public function it_can_serialize_a_json_string_to_pretty_json() { $driver = new JsonDriver(); @@ -24,7 +27,7 @@ public function it_can_serialize_a_json_string_to_pretty_json() $this->assertEquals($expected, $driver->serialize('{"foo":"bar"}')); } - /** @test */ + #[Test] public function it_can_serialize_a_json_hash_to_pretty_json() { $driver = new JsonDriver(); @@ -70,7 +73,7 @@ public function it_can_serialize_a_json_hash_to_pretty_json() ])); } - /** @test */ + #[Test] public function it_can_serialize_a_json_array_to_pretty_json() { $driver = new JsonDriver(); @@ -87,7 +90,7 @@ public function it_can_serialize_a_json_array_to_pretty_json() $this->assertEquals($expected, $driver->serialize(['foo', 'bar', 'baz'])); } - /** @test */ + #[Test] public function it_can_serialize_a_empty_json_object_to_pretty_json() { $driver = new JsonDriver(); @@ -110,7 +113,7 @@ public function it_can_serialize_a_empty_json_object_to_pretty_json() ])); } - /** @test */ + #[Test] public function it_can_not_serialize_resources() { $driver = new JsonDriver(); @@ -122,20 +125,17 @@ public function it_can_not_serialize_resources() $driver->serialize($resource); } - /** - * @test - * - * @testWith ["{}", "{}", true] - * ["{}", "{\"data\":1}", false] - * ["{\"data\":1}", "{\"data\":1}", true] - * ["{\"data\":1}", "{\"data\":\"1\"}", false] - * ["true", "true", true] - * ["false", "false", true] - * ["null", "null", true] - * ["1", "1", true] - * ["1.1", "1.1", true] - * ["{\"empty\": []}", "{\"empty\":{}}", false] - */ + #[Test] + #[TestWith(["{}", "{}", true])] + #[TestWith(["{}", "{\"data\":1}", false])] + #[TestWith(["{\"data\":1}", "{\"data\":1}", true])] + #[TestWith(["{\"data\":1}", "{\"data\":\"1\"}", false])] + #[TestWith(["true", "true", true])] + #[TestWith(["false", "false", true])] + #[TestWith(["null", "null", true])] + #[TestWith(["1", "1", true])] + #[TestWith(["1.1", "1.1", true])] + #[TestWith(["{\"empty\": []}", "{\"empty\":{}}", false])] public function it_can_match_json_strings(string $expected, string $actual, bool $assertion) { $driver = new JsonDriver(); diff --git a/tests/Unit/Drivers/ObjectDriverTest.php b/tests/Unit/Drivers/ObjectDriverTest.php index 3d06f87..8a5a535 100644 --- a/tests/Unit/Drivers/ObjectDriverTest.php +++ b/tests/Unit/Drivers/ObjectDriverTest.php @@ -2,12 +2,13 @@ namespace Spatie\Snapshots\Test\Unit\Drivers; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Drivers\ObjectDriver; class ObjectDriverTest extends TestCase { - /** @test */ + #[Test] public function it_can_serialize_a_string() { $driver = new ObjectDriver(); @@ -15,7 +16,7 @@ public function it_can_serialize_a_string() $this->assertEquals('foo', $driver->serialize('foo')); } - /** @test */ + #[Test] public function it_can_serialize_an_integer() { $driver = new ObjectDriver(); @@ -23,7 +24,7 @@ public function it_can_serialize_an_integer() $this->assertEquals('1', $driver->serialize(1)); } - /** @test */ + #[Test] public function it_can_serialize_a_float() { $driver = new ObjectDriver(); @@ -31,7 +32,7 @@ public function it_can_serialize_a_float() $this->assertEquals('1.5', $driver->serialize(1.5)); } - /** @test */ + #[Test] public function it_can_serialize_an_associative_array() { $driver = new ObjectDriver(); @@ -45,7 +46,7 @@ public function it_can_serialize_an_associative_array() $this->assertEquals($expected, $driver->serialize(['foo' => ['bar' => 'baz']])); } - /** @test */ + #[Test] public function it_can_serialize_an_indexed_array_without_keys() { $driver = new ObjectDriver(); @@ -59,7 +60,7 @@ public function it_can_serialize_an_indexed_array_without_keys() $this->assertEquals($expected, $driver->serialize(['foo', 'bar'])); } - /** @test */ + #[Test] public function it_can_serialize_a_simple_object() { $driver = new ObjectDriver(); @@ -72,7 +73,7 @@ public function it_can_serialize_a_simple_object() $this->assertEquals($expected, $driver->serialize((object) ['foo' => 'bar'])); } - /** @test */ + #[Test] public function it_can_serialize_a_class_instance() { $driver = new ObjectDriver(); diff --git a/tests/Unit/Drivers/TextDriverTest.php b/tests/Unit/Drivers/TextDriverTest.php index 3b4a455..04cc4d7 100644 --- a/tests/Unit/Drivers/TextDriverTest.php +++ b/tests/Unit/Drivers/TextDriverTest.php @@ -2,12 +2,13 @@ namespace Spatie\Snapshots\Test\Unit\Drivers; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Drivers\TextDriver; class TextDriverTest extends TestCase { - /** @test */ + #[Test] public function it_can_serialize_laravel_route_list() { $driver = new TextDriver(); @@ -27,7 +28,7 @@ public function it_can_serialize_laravel_route_list() EOF)); } - /** @test */ + #[Test] public function it_can_serialize_when_given_OS_dependant_line_endings() { $driver = new TextDriver(); diff --git a/tests/Unit/Drivers/XmlDriverTest.php b/tests/Unit/Drivers/XmlDriverTest.php index 4f0537d..3ac3068 100644 --- a/tests/Unit/Drivers/XmlDriverTest.php +++ b/tests/Unit/Drivers/XmlDriverTest.php @@ -2,13 +2,14 @@ namespace Spatie\Snapshots\Test\Unit\Drivers; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Drivers\XmlDriver; use Spatie\Snapshots\Exceptions\CantBeSerialized; class XmlDriverTest extends TestCase { - /** @test */ + #[Test] public function it_can_serialize_a_xml_string_to_pretty_xml() { $driver = new XmlDriver(); @@ -24,7 +25,7 @@ public function it_can_serialize_a_xml_string_to_pretty_xml() $this->assertEquals($expected, $driver->serialize('baz')); } - /** @test */ + #[Test] public function it_can_only_serialize_strings() { $driver = new XmlDriver(); diff --git a/tests/Unit/Drivers/YamlDriverTest.php b/tests/Unit/Drivers/YamlDriverTest.php index dade4df..f01d2f5 100644 --- a/tests/Unit/Drivers/YamlDriverTest.php +++ b/tests/Unit/Drivers/YamlDriverTest.php @@ -2,12 +2,13 @@ namespace Spatie\Snapshots\Test\Unit\Drivers; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Drivers\YamlDriver; class YamlDriverTest extends TestCase { - /** @test */ + #[Test] public function it_can_serialize_a_yaml_string() { $driver = new YamlDriver(); @@ -21,7 +22,7 @@ public function it_can_serialize_a_yaml_string() $this->assertEquals($yamlString, $driver->serialize($yamlString)); } - /** @test */ + #[Test] public function it_can_serialize_a_yaml_array() { $driver = new YamlDriver(); diff --git a/tests/Unit/FilenameTest.php b/tests/Unit/FilenameTest.php index 30413e7..939039b 100644 --- a/tests/Unit/FilenameTest.php +++ b/tests/Unit/FilenameTest.php @@ -2,16 +2,15 @@ namespace Spatie\Snapshots\Test\Unit; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Filename; class FilenameTest extends TestCase { - /** - * @test - * - * @dataProvider fileNameProvider - */ + #[Test] + #[DataProvider('fileNameProvider')] public function it_creates_a_filename_which_is_valid_on_all_systems($name, $expected) { $this->assertEquals($expected, Filename::cleanFilename($name)); diff --git a/tests/Unit/SnapshotTest.php b/tests/Unit/SnapshotTest.php index 5f80bdc..6b07ea2 100644 --- a/tests/Unit/SnapshotTest.php +++ b/tests/Unit/SnapshotTest.php @@ -2,6 +2,7 @@ namespace Spatie\Snapshots\Test\Unit; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\Driver; use Spatie\Snapshots\Filesystem; @@ -23,7 +24,7 @@ public function setUp(): void $this->driver = $this->createMock(Driver::class); } - /** @test */ + #[Test] public function it_has_an_id() { $snapshot = new Snapshot('abc', $this->filesystem, $this->driver); @@ -31,7 +32,7 @@ public function it_has_an_id() $this->assertEquals('abc', $snapshot->id()); } - /** @test */ + #[Test] public function it_has_a_filename_based_on_its_id_and_its_drivers_extension() { $this->driver @@ -44,7 +45,7 @@ public function it_has_a_filename_based_on_its_id_and_its_drivers_extension() $this->assertEquals('abc.php', $snapshot->filename()); } - /** @test */ + #[Test] public function it_has_a_filename_which_is_valid_on_all_systems() { $this->driver