From 41eb2d517a9225a0ace1e9c531849a15f8e0fb82 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 20 Jan 2023 23:31:01 +0800 Subject: [PATCH 1/3] Add PHPUnit dev dep and class alias for older versions --- composer.json | 3 +++ tests/bootstrap.php | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/composer.json b/composer.json index 7d555a3..1c6db1a 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,9 @@ "require": { "php": ">=5.3" }, + "require-dev": { + "phpunit/phpunit": "^4|^5|^6|^7|^8|^9" + }, "autoload": { "psr-0": { "dflydev\\util\\antPathMatcher": "src" } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 205b408..95126d2 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -10,3 +10,7 @@ $loader = require dirname(__DIR__).'/vendor/autoload.php'; $loader->add('dflydev\\tests\\util\\antPathMatcher', 'tests'); + +if (class_exists('PHPUnit\Framework\TestCase') && ! class_exists('PHPUnit_Framework_TestCase')) { + class_alias('PHPUnit\Framework\TestCase', 'PHPUnit_Framework_TestCase'); +} From cbae583416e5adc6b294786cbb9a43a3141813a5 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 20 Jan 2023 23:33:17 +0800 Subject: [PATCH 2/3] Remove "test" prefix from data provider method This prevents PHPUnit from executing the data provider as a test and warning that it performs no assertions. --- .../dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php b/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php index 296591b..3b3944a 100644 --- a/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php +++ b/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php @@ -30,7 +30,7 @@ public function testLeadingPathCharacterMismatch() { } /** - * @dataProvider testMatchesProvider + * @dataProvider provideMatches */ public function testMatches($pattern, $shouldMatch, $shouldNotMatch) { @@ -48,7 +48,7 @@ public function formatTestMatchesMessage($pattern, $path) return 'Testing path "' . $path . '" against pattern "' . $pattern . '"'; } - public function testMatchesProvider() + public function provideMatches() { return array( array( From 0cb74fbecf0780bafcd8bfc6f40425b49aef47d2 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 20 Jan 2023 23:34:29 +0800 Subject: [PATCH 3/3] Use start/end anchors in matchStrings() regex This adds a new test case demonstrating the issue where "com/**" would incorrectly match "com2/foo" or "2com/foo". The change also necessitated revising an existing test case, since "t?st" should not match a string with a file extension. The original test case was changed to add an extension to the pattern, and the extension-less pattern was preserved for a new regression test. --- src/dflydev/util/antPathMatcher/AntPathMatcher.php | 2 +- .../tests/util/antPathMatcher/AntPathMatcherTest.php | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/dflydev/util/antPathMatcher/AntPathMatcher.php b/src/dflydev/util/antPathMatcher/AntPathMatcher.php index 42a4509..a4d81b6 100644 --- a/src/dflydev/util/antPathMatcher/AntPathMatcher.php +++ b/src/dflydev/util/antPathMatcher/AntPathMatcher.php @@ -221,7 +221,7 @@ protected function matchStrings($pattern, $str) { $re = preg_replace_callback('([\?\*\.\+])', array($this, 'matchStringsCallback'), $pattern); - return preg_match('/'.$re.'/', $str); + return preg_match('/^'.$re.'$/', $str); } } diff --git a/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php b/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php index 3b3944a..35e8b64 100644 --- a/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php +++ b/tests/dflydev/tests/util/antPathMatcher/AntPathMatcherTest.php @@ -53,6 +53,11 @@ public function provideMatches() return array( array( 'com/t?st', + array('com/test', 'com/tast', 'com/txst'), + array('com/test.jsp', 'com/tast.jsp', 'com/txst.jsp'), + ), + array( + 'com/t?st.jsp', array('com/test.jsp', 'com/tast.jsp', 'com/txst.jsp'), array('com/toast.jsp', 'com/README.md') ), @@ -95,7 +100,12 @@ public function provideMatches() 'com/foo/', array('com/foo/bar.jsp','com/foo/bar/baz.jsp',), array('com.txt', 'com/foo.txt'), - ) + ), + array( + 'com/**', + array('com/foo'), + array('com2/foo', '_com/foo'), + ), ); }