Skip to content

Commit

Permalink
Updated PHPUnit to v11
Browse files Browse the repository at this point in the history
  • Loading branch information
PHLAK committed Dec 4, 2024
1 parent 871f180 commit bc42497
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 36 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
64 changes: 43 additions & 21 deletions tests/GlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -94,15 +102,17 @@ 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('[[?*\]', '*'));
$this->assertTrue(Glob::match('[[?*\]', '\\'));
$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'));
Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -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('\\');

Expand All @@ -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('\\');

Expand All @@ -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'));
Expand All @@ -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'));
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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');

Expand Down
38 changes: 28 additions & 10 deletions tests/PatternTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -61,15 +75,17 @@ 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());
$this->assertEquals('#^[^/]*\.txt(?=\.(gz|xz))$#', Pattern::make('*.txt(=.{gz,xz})')->toRegex());
$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));
Expand All @@ -78,15 +94,17 @@ 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('\\');

$this->assertEquals('#^[^\\\\]*$#', Pattern::make('*')->toRegex());
$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('?'));
Expand Down
5 changes: 1 addition & 4 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,4 @@

use Yoast\PHPUnitPolyfills\TestCases\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
protected $backupStaticAttributes = true;
}
abstract class TestCase extends BaseTestCase {}

0 comments on commit bc42497

Please sign in to comment.