From bc4249737bbb5e2e7b2754cc0c52c5b59008c855 Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Wed, 4 Dec 2024 10:36:57 -0700 Subject: [PATCH] Updated PHPUnit to v11 --- composer.json | 2 +- tests/GlobTest.php | 64 +++++++++++++++++++++++++++++-------------- tests/PatternTest.php | 38 ++++++++++++++++++------- tests/TestCase.php | 5 +--- 4 files changed, 73 insertions(+), 36 deletions(-) diff --git a/composer.json b/composer.json index 3ddd313..c5f600f 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ "php": ">=8.2", "phlak/coding-standards": "^3.0", "phpstan/phpstan": "^2.0", - "phpunit/phpunit": "^9.0", + "phpunit/phpunit": "^11.0", "psy/psysh": "^0.12.5", "symfony/var-dumper": "^6.0", "yoast/phpunit-polyfills": "^3.0" diff --git a/tests/GlobTest.php b/tests/GlobTest.php index ff63e1d..60f5877 100644 --- a/tests/GlobTest.php +++ b/tests/GlobTest.php @@ -4,19 +4,23 @@ use PHLAK\Splat\Glob; use PHLAK\Splat\Pattern; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; -/** @covers \PHLAK\Splat\Glob */ +#[CoversClass(Glob::class)] class GlobTest extends TestCase { - public function test_it_matches_a_literal_value(): void + #[Test] + public function it_matches_a_literal_value(): void { $this->assertTrue(Glob::match('foo', 'foo')); $this->assertFalse(Glob::match('bar', 'foo')); } - public function test_it_matches_a_single_character(): void + #[Test] + public function it_matches_a_single_character(): void { $this->assertTrue(Glob::match('?', 'f')); $this->assertTrue(Glob::match('??', 'fo')); @@ -26,7 +30,8 @@ public function test_it_matches_a_single_character(): void $this->assertFalse(Glob::match('???', 'f')); } - public function test_it_matches_zero_or_more_characters_excluding_slash(): void + #[Test] + public function it_matches_zero_or_more_characters_excluding_slash(): void { $this->assertTrue(Glob::match('*', 'foo')); $this->assertTrue(Glob::match('*', 'foo\\bar')); @@ -40,7 +45,8 @@ public function test_it_matches_zero_or_more_characters_excluding_slash(): void $this->assertFalse(Glob::match('*/*.txt', 'foo/bar/baz.txt')); } - public function test_it_matches_zero_or_more_characeters_including_slash(): void + #[Test] + public function it_matches_zero_or_more_characeters_including_slash(): void { $this->assertTrue(Glob::match('**', 'foo')); $this->assertTrue(Glob::match('**', 'foo.txt')); @@ -54,7 +60,8 @@ public function test_it_matches_zero_or_more_characeters_including_slash(): void $this->assertFalse(Glob::match('**/*.txt', 'foo.txt')); } - public function test_it_matches_a_single_character_from_a_set(): void + #[Test] + public function it_matches_a_single_character_from_a_set(): void { $this->assertTrue(Glob::match('[abc]', 'a')); $this->assertTrue(Glob::match('[abc]', 'b')); @@ -74,7 +81,8 @@ public function test_it_matches_a_single_character_from_a_set(): void $this->assertFalse(Glob::match('[abc][abc]', 'abc')); } - public function test_it_matches_a_single_character_in_a_range(): void + #[Test] + public function it_matches_a_single_character_in_a_range(): void { $this->assertTrue(Glob::match('[a-c]', 'a')); $this->assertTrue(Glob::match('[a-c]', 'b')); @@ -94,7 +102,8 @@ public function test_it_matches_a_single_character_in_a_range(): void $this->assertFalse(Glob::match('[a-c][a-c]', 'abc')); } - public function test_it_matches_glob_wildcards_literally_in_character_classes(): void + #[Test] + public function it_matches_glob_wildcards_literally_in_character_classes(): void { $this->assertTrue(Glob::match('[[?*\]', '?')); $this->assertTrue(Glob::match('[[?*\]', '*')); @@ -102,7 +111,8 @@ public function test_it_matches_glob_wildcards_literally_in_character_classes(): $this->assertFalse(Glob::match('[[?*\]', 'x')); } - public function test_it_matches_any_character_not_in_a_set(): void + #[Test] + public function it_matches_any_character_not_in_a_set(): void { $this->assertTrue(Glob::match('[^abc]', 'x')); $this->assertTrue(Glob::match('[^abc]', 'z')); @@ -121,7 +131,8 @@ public function test_it_matches_any_character_not_in_a_set(): void $this->assertFalse(Glob::match('[^abc][^xyz]', 'foo')); } - public function test_it_matches_any_character_not_in_a_range(): void + #[Test] + public function it_matches_any_character_not_in_a_range(): void { $this->assertTrue(Glob::match('[^a-c]', 'x')); $this->assertTrue(Glob::match('[^a-c]', 'z')); @@ -140,7 +151,8 @@ public function test_it_matches_any_character_not_in_a_range(): void $this->assertFalse(Glob::match('[^a-c][^x-z]', 'foo')); } - public function test_it_matches_a_pattern_from_a_set(): void + #[Test] + public function it_matches_a_pattern_from_a_set(): void { $this->assertTrue(Glob::match('{foo,bar,baz}', 'foo')); $this->assertTrue(Glob::match('{foo,bar,baz}', 'bar')); @@ -155,25 +167,29 @@ public function test_it_matches_a_pattern_from_a_set(): void $this->assertFalse(Glob::match('{foo,bar,baz}', 'qux')); } - public function test_it_matches_the_start_of_a_string(): void + #[Test] + public function it_matches_the_start_of_a_string(): void { $this->assertTrue(Glob::matchStart('foo/*', 'foo/bar.txt')); $this->assertFalse(Glob::matchStart('foo/*', 'bar/foo.txt')); } - public function test_it_matches_the_end_of_a_string(): void + #[Test] + public function it_matches_the_end_of_a_string(): void { $this->assertTrue(Glob::matchEnd('**.txt', 'foo/bar.txt')); $this->assertFalse(Glob::matchEnd('**.txt', 'foo/bar.log')); } - public function test_it_matches_within_a_string(): void + #[Test] + public function it_matches_within_a_string(): void { $this->assertTrue(Glob::matchWithin('*/bar/*', 'foo/bar/baz.txt')); $this->assertFalse(Glob::matchWithin('*/bar/*', 'foo/baz/qux.txt')); } - public function test_it_matches_zero_or_more_characters_excluding_back_slash(): void + #[Test] + public function it_matches_zero_or_more_characters_excluding_back_slash(): void { Pattern::directorySeparator('\\'); @@ -191,7 +207,8 @@ public function test_it_matches_zero_or_more_characters_excluding_back_slash(): $this->assertFalse(Glob::match('*\\*.txt', 'foo\\bar\\baz.txt')); } - public function test_it_matches_zero_or_more_characeters_including_back_slash(): void + #[Test] + public function it_matches_zero_or_more_characeters_including_back_slash(): void { Pattern::directorySeparator('\\'); @@ -207,7 +224,8 @@ public function test_it_matches_zero_or_more_characeters_including_back_slash(): $this->assertFalse(Glob::match('**\\\\*.txt', 'foo.txt')); } - public function test_it_can_match_a_string_with_a_lookahead(): void + #[Test] + public function it_can_match_a_string_with_a_lookahead(): void { $this->assertTrue(Glob::matchWithin('*.tar(=.gz)', 'foo.tar.gz')); $this->assertFalse(Glob::matchWithin('*.tar(=.gz)', 'foo.tar.xz')); @@ -219,7 +237,8 @@ public function test_it_can_match_a_string_with_a_lookahead(): void $this->assertFalse(Glob::matchWithin('*.tar(=.{gz,xz})', 'foo.tar')); } - public function test_it_can_match_a_string_with_a_negative_lookahead(): void + #[Test] + public function it_can_match_a_string_with_a_negative_lookahead(): void { $this->assertTrue(Glob::matchWithin('*.tar(!.gz)', 'foo.tar')); $this->assertTrue(Glob::matchWithin('*.tar(!.gz)', 'foo.tar.xz')); @@ -231,7 +250,8 @@ public function test_it_can_match_a_string_with_a_negative_lookahead(): void $this->assertFalse(Glob::matchWithin('*.tar(!.{gz,xz})', 'foo.tar.xz')); } - public function test_it_can_filter_an_array(): void + #[Test] + public function it_can_filter_an_array(): void { $filtered = Glob::filter('**.txt', [ 'foo', 'foo.txt', 'bar.zip', 'foo/bar.png', 'foo/bar.txt', @@ -240,7 +260,8 @@ public function test_it_can_filter_an_array(): void $this->assertEquals(['foo.txt', 'foo/bar.txt'], array_values($filtered)); } - public function test_it_can_reject_an_array(): void + #[Test] + public function it_can_reject_an_array(): void { $rejected = Glob::reject('**.txt', [ 'foo', 'foo.txt', 'bar.zip', 'foo/bar.png', 'foo/bar.txt', @@ -249,7 +270,8 @@ public function test_it_can_reject_an_array(): void $this->assertEquals(['foo', 'bar.zip', 'foo/bar.png'], array_values($rejected)); } - public function test_it_can_return_a_list_of_files_matching_the_pattern(): void + #[Test] + public function it_can_return_a_list_of_files_matching_the_pattern(): void { $files = Glob::in('**.txt', __DIR__ . '/_files'); diff --git a/tests/PatternTest.php b/tests/PatternTest.php index 7698c9d..d5dd064 100644 --- a/tests/PatternTest.php +++ b/tests/PatternTest.php @@ -3,25 +3,37 @@ namespace Tests; use PHLAK\Splat\Pattern; +use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\Test; -/** @covers \PHLAK\Splat\Pattern */ +#[CoversClass(Pattern::class)] class PatternTest extends TestCase { - public function test_it_is_stringable(): void + protected function setUp(): void + { + parent::setUp(); + + Pattern::directorySeparator('/'); + } + + #[Test] + public function it_is_stringable(): void { $this->assertEquals('foo.txt', (string) Pattern::make('foo.txt')); $this->assertEquals('**.txt', (string) Pattern::make('**.txt')); $this->assertEquals('foo.{yml,yaml}', (string) Pattern::make('foo.{yml,yaml}')); } - public function test_it_can_convert_a_litteral_string_to_a_regular_expression(): void + #[Test] + public function it_can_convert_a_litteral_string_to_a_regular_expression(): void { $this->assertEquals('#^foo$#', Pattern::make('foo')->toRegex()); $this->assertEquals('#^foo/bar$#', Pattern::make('foo/bar')->toRegex()); $this->assertEquals('#^foo/bar\.txt$#', Pattern::make('foo/bar.txt')->toRegex()); } - public function test_it_converts_glob_patterns_to_regular_expression_patterns(): void + #[Test] + public function it_converts_glob_patterns_to_regular_expression_patterns(): void { $this->assertEquals('#^$#', Pattern::make('')->toRegex()); $this->assertEquals('#^.$#', Pattern::make('?')->toRegex()); @@ -33,7 +45,8 @@ public function test_it_converts_glob_patterns_to_regular_expression_patterns(): $this->assertEquals('#^(?!)$#', Pattern::make('(!)')->toRegex()); } - public function test_it_can_escape_glob_patterns_when_converting_to_regular_expressions(): void + #[Test] + public function it_can_escape_glob_patterns_when_converting_to_regular_expressions(): void { $this->assertEquals('#^\\\\$#', Pattern::make('\\\\')->toRegex()); $this->assertEquals('#^\\?$#', Pattern::make('\?')->toRegex()); @@ -42,7 +55,8 @@ public function test_it_can_escape_glob_patterns_when_converting_to_regular_expr $this->assertEquals('#^\\#$#', Pattern::make('\#')->toRegex()); } - public function test_it_can_convert_a_complex_glob_pattern_to_a_regular_expressions(): void + #[Test] + public function it_can_convert_a_complex_glob_pattern_to_a_regular_expressions(): void { $this->assertEquals('#^foo\.txt$#', Pattern::make('foo.txt')->toRegex()); $this->assertEquals('#^foo/bar\.txt$#', Pattern::make('foo/bar.txt')->toRegex()); @@ -61,7 +75,8 @@ public function test_it_can_convert_a_complex_glob_pattern_to_a_regular_expressi $this->assertEquals('#^foo/.*/[^/]*\.txt$#', Pattern::make('foo/**/*.txt')->toRegex()); } - public function test_it_can_convert_a_glob_pattern_with_lookaheads(): void + #[Test] + public function it_can_convert_a_glob_pattern_with_lookaheads(): void { $this->assertEquals('#^[^/]*\.txt(?=\.gz)$#', Pattern::make('*.txt(=.gz)')->toRegex()); $this->assertEquals('#^[^/]*\.txt(?!\.gz)$#', Pattern::make('*.txt(!.gz)')->toRegex()); @@ -69,7 +84,8 @@ public function test_it_can_convert_a_glob_pattern_with_lookaheads(): void $this->assertEquals('#^[^/]*\.txt(?!\.(gz|xz))$#', Pattern::make('*.txt(!.{gz,xz})')->toRegex()); } - public function test_regular_expression_start_and_end_anchors_are_configurable(): void + #[Test] + public function regular_expression_start_and_end_anchors_are_configurable(): void { $this->assertEquals('#foo#', Pattern::make('foo')->toRegex(Pattern::NO_ANCHORS)); $this->assertEquals('#^foo#', Pattern::make('foo')->toRegex(Pattern::START_ANCHOR)); @@ -78,7 +94,8 @@ public function test_regular_expression_start_and_end_anchors_are_configurable() $this->assertEquals('#^foo$#', Pattern::make('foo')->toRegex(Pattern::START_ANCHOR | Pattern::END_ANCHOR)); } - public function test_it_can_use_back_slash_as_the_directory_separator(): void + #[Test] + public function it_can_use_back_slash_as_the_directory_separator(): void { Pattern::directorySeparator('\\'); @@ -86,7 +103,8 @@ public function test_it_can_use_back_slash_as_the_directory_separator(): void $this->assertEquals('#^.*$#', Pattern::make('**')->toRegex()); } - public function test_it_can_escape_a_glob_string(): void + #[Test] + public function it_can_escape_a_glob_string(): void { $this->assertEquals('\\\\', Pattern::escape('\\')); $this->assertEquals('\\?', Pattern::escape('?')); diff --git a/tests/TestCase.php b/tests/TestCase.php index 24ade23..16ed4b1 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -4,7 +4,4 @@ use Yoast\PHPUnitPolyfills\TestCases\TestCase as BaseTestCase; -abstract class TestCase extends BaseTestCase -{ - protected $backupStaticAttributes = true; -} +abstract class TestCase extends BaseTestCase {}