From 5c17f47536556d414091fa8b0631fb950c748b79 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 14 Jun 2023 15:56:44 +0000 Subject: [PATCH 1/4] chore(deps-dev): update rector/rector requirement from 0.17.0 to 0.17.1 Updates the requirements on [rector/rector](https://github.com/rectorphp/rector) to permit the latest version. - [Release notes](https://github.com/rectorphp/rector/releases) - [Commits](https://github.com/rectorphp/rector/compare/0.17.0...0.17.1) --- updated-dependencies: - dependency-name: rector/rector dependency-type: direct:development ... Signed-off-by: dependabot[bot] --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 49e50bfc7413..08c6d72d8d18 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "phpunit/phpcov": "^8.2", "phpunit/phpunit": "^9.1", "predis/predis": "^1.1 || ^2.0", - "rector/rector": "0.17.0", + "rector/rector": "0.17.1", "vimeo/psalm": "^5.0" }, "suggest": { From f658272c7b06ead493a81ab39d5a49cdf21fdf76 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 14 Jun 2023 23:01:49 +0700 Subject: [PATCH 2/4] update rector config and re-run rector --- rector.php | 8 ------ system/Database/OCI8/Connection.php | 2 +- system/Helpers/text_helper.php | 2 +- system/Router/RouteCollection.php | 2 +- .../Routes/SampleURIGeneratorTest.php | 2 +- tests/system/Database/Builder/SelectTest.php | 6 ++--- tests/system/Database/RawSqlTest.php | 4 +-- tests/system/Router/RouteCollectionTest.php | 25 ++++++++++--------- tests/system/Validation/FormatRulesTest.php | 4 +-- tests/system/Validation/ValidationTest.php | 20 +++++++-------- 10 files changed, 34 insertions(+), 41 deletions(-) diff --git a/rector.php b/rector.php index cf6985af1488..2356339cb93b 100644 --- a/rector.php +++ b/rector.php @@ -29,7 +29,6 @@ use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector; -use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector; use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; @@ -43,7 +42,6 @@ use Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector; use Rector\PHPUnit\Set\PHPUnitSetList; use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; -use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector; use Rector\Set\ValueObject\LevelSetList; use Rector\Set\ValueObject\SetList; use Utils\Rector\PassStrictParameterToFunctionParameterRector; @@ -94,11 +92,6 @@ __DIR__ . '/system/Router/AutoRouterImproved.php', ], - // call on purpose for nothing happen check - RemoveEmptyMethodCallRector::class => [ - __DIR__ . '/tests', - ], - // check on constant compare UnwrapFutureCompatibleIfPhpVersionRector::class => [ __DIR__ . '/system/Autoloader/Autoloader.php', @@ -147,7 +140,6 @@ $rectorConfig->rule(FuncGetArgsToVariadicParamRector::class); $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); - $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); $rectorConfig->rule(StringClassNameToClassConstantRector::class); $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); $rectorConfig->rule(CompleteDynamicPropertiesRector::class); diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index ce6554ddc63a..ee5b48a8b37a 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -53,7 +53,7 @@ class Connection extends BaseConnection protected $validDSNs = [ 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS // Easy Connect string (Oracle 10g+) - 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', + 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9]\d{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', 'in' => '/^[a-z0-9$_]+$/i', // Instance name (defined in tnsnames.ora) ]; diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 2343a89bfafe..8f96b423b02b 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -662,7 +662,7 @@ function _from_random(int $length, string $pool): string */ function increment_string(string $str, string $separator = '_', int $first = 1): string { - preg_match('/(.+)' . preg_quote($separator, '/') . '([0-9]+)$/', $str, $match); + preg_match('/(.+)' . preg_quote($separator, '/') . '(\d+)$/', $str, $match); return isset($match[2]) ? $match[1] . $separator . ((int) $match[2] + 1) : $str . $separator . $first; } diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index 66724935e31c..ab3066f9eff4 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -98,7 +98,7 @@ class RouteCollection implements RouteCollectionInterface 'any' => '.*', 'segment' => '[^/]+', 'alphanum' => '[a-zA-Z0-9]+', - 'num' => '[0-9]+', + 'num' => '\d+', 'alpha' => '[a-zA-Z]+', 'hash' => '[^/]+', ]; diff --git a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php index 4b7b8fa3e814..8c64a72ab198 100644 --- a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php +++ b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php @@ -38,7 +38,7 @@ public function routeKeyProvider(): Generator { yield from [ 'root' => ['/', '/'], - 'placeholder num' => ['shop/product/([0-9]+)', 'shop/product/123'], + 'placeholder num' => ['shop/product/(\d+)', 'shop/product/123'], 'placeholder segment' => ['shop/product/([^/]+)', 'shop/product/abc_123'], 'placeholder any' => ['shop/product/(.*)', 'shop/product/123/abc'], 'auto route' => ['home/index[/...]', 'home/index/1/2/3/4/5'], diff --git a/tests/system/Database/Builder/SelectTest.php b/tests/system/Database/Builder/SelectTest.php index af7bf96d119e..5f92d6f5f5ed 100644 --- a/tests/system/Database/Builder/SelectTest.php +++ b/tests/system/Database/Builder/SelectTest.php @@ -105,7 +105,7 @@ public function testSelectWorksWithRawSql() { $builder = new BaseBuilder('users', $this->db); - $sql = 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral'; + $sql = 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral'; $builder->select(new RawSql($sql)); $expected = 'SELECT ' . $sql . ' FROM "users"'; @@ -134,12 +134,12 @@ public function testSelectRegularExpressionWorksWithEscpaeFalse() $builder = new BaseBuilder('ob_human_resources', $this->db); $builder->select( - 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral', + 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral', false ); $expected = <<<'SQL' - SELECT REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral + SELECT REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral FROM "ob_human_resources" SQL; $this->assertSame($expected, $builder->getCompiledSelect()); diff --git a/tests/system/Database/RawSqlTest.php b/tests/system/Database/RawSqlTest.php index 695a63980e89..b28b0b6ecfea 100644 --- a/tests/system/Database/RawSqlTest.php +++ b/tests/system/Database/RawSqlTest.php @@ -22,7 +22,7 @@ final class RawSqlTest extends CIUnitTestCase { public function testCanConvertToString() { - $expected = 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral'; + $expected = 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral'; $rawSql = new RawSql($expected); $this->assertSame($expected, (string) $rawSql); @@ -47,6 +47,6 @@ public function testGetBindingKey() $key = $rawSql->getBindingKey(); - $this->assertMatchesRegularExpression('/\ARawSql[0-9]+\z/', $key); + $this->assertMatchesRegularExpression('/\ARawSql\d+\z/', $key); } } diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 6458449a02c9..a37d98f1c6e2 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Router; use CodeIgniter\Config\Services; +use CodeIgniter\controller; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; @@ -88,7 +89,7 @@ public function testBasicAddCallableWithParamsString() $routes = $routes->getRoutes(); $expects = [ - 'product/([0-9]+)/([0-9]+)' => '\Tests\Support\Controllers\Hello::index/$2/$1', + 'product/(\d+)/(\d+)' => '\Tests\Support\Controllers\Hello::index/$2/$1', ]; $this->assertSame($expects, $routes); } @@ -101,7 +102,7 @@ public function testBasicAddCallableWithParamsWithoutString() $routes = $routes->getRoutes(); $expects = [ - 'product/([0-9]+)/([0-9]+)' => '\Tests\Support\Controllers\Hello::index/$1/$2', + 'product/(\d+)/(\d+)' => '\Tests\Support\Controllers\Hello::index/$1/$2', ]; $this->assertSame($expects, $routes); } @@ -237,7 +238,7 @@ public function testAddRecognizesCustomNamespaces() $routes->add('home', 'controller'); $expects = [ - 'home' => '\CodeIgniter\controller', + 'home' => '\\' . controller::class, ]; $routes = $routes->getRoutes(); @@ -615,10 +616,10 @@ public function testResourcesWithCustomPlaceholder() $routes->resource('photos', ['placeholder' => ':num']); $expected = [ - 'photos' => '\Photos::index', - 'photos/new' => '\Photos::new', - 'photos/([0-9]+)/edit' => '\Photos::edit/$1', - 'photos/([0-9]+)' => '\Photos::show/$1', + 'photos' => '\Photos::index', + 'photos/new' => '\Photos::new', + 'photos/(\d+)/edit' => '\Photos::edit/$1', + 'photos/(\d+)' => '\Photos::show/$1', ]; $this->assertSame($expected, $routes->getRoutes()); @@ -633,10 +634,10 @@ public function testResourcesWithDefaultPlaceholder() $routes->resource('photos'); $expected = [ - 'photos' => '\Photos::index', - 'photos/new' => '\Photos::new', - 'photos/([0-9]+)/edit' => '\Photos::edit/$1', - 'photos/([0-9]+)' => '\Photos::show/$1', + 'photos' => '\Photos::index', + 'photos/new' => '\Photos::new', + 'photos/(\d+)/edit' => '\Photos::edit/$1', + 'photos/(\d+)' => '\Photos::show/$1', ]; $this->assertSame($expected, $routes->getRoutes()); @@ -1399,7 +1400,7 @@ public function testOffsetParameters() $routes = $this->getCollector(); $routes->get('users/(:num)', 'users/show/$1', ['offset' => 1]); - $expected = ['users/([0-9]+)' => '\users/show/$2']; + $expected = ['users/(\d+)' => '\users/show/$2']; $this->assertSame($expected, $routes->getRoutes()); } diff --git a/tests/system/Validation/FormatRulesTest.php b/tests/system/Validation/FormatRulesTest.php index 8e78750e494e..856a797f2911 100644 --- a/tests/system/Validation/FormatRulesTest.php +++ b/tests/system/Validation/FormatRulesTest.php @@ -63,7 +63,7 @@ public function testRegexMatch(): void $this->validation->setRules([ 'foo' => 'regex_match[/[a-z]/]', - 'phone' => 'regex_match[/^(01[2689]|09)[0-9]{8}$/]', + 'phone' => 'regex_match[/^(01[2689]|09)\d{8}$/]', ]); $this->assertTrue($this->validation->run($data)); @@ -78,7 +78,7 @@ public function testRegexMatchFalse(): void $this->validation->setRules([ 'foo' => 'regex_match[\d]', - 'phone' => 'regex_match[/^(01[2689]|09)[0-9]{8}$/]', + 'phone' => 'regex_match[/^(01[2689]|09)\d{8}$/]', ]); $this->assertFalse($this->validation->run($data)); diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index efc00290ebd4..1ca2e8970425 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -883,7 +883,7 @@ public function testHasError(): void public function testSplitRulesTrue(): void { $this->validation->setRules([ - 'phone' => 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric', + 'phone' => 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric', ]); $this->assertTrue($this->validation->run(['phone' => '0987654321'])); } @@ -891,7 +891,7 @@ public function testSplitRulesTrue(): void public function testSplitRulesFalse(): void { $this->validation->setRules([ - 'phone' => 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric', + 'phone' => 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric', ]); $this->assertFalse($this->validation->run(['phone' => '09876543214'])); } @@ -909,8 +909,8 @@ public function testSplitNotRegex(): void public function testSplitRegex(): void { $method = $this->getPrivateMethodInvoker($this->validation, 'splitRules'); - $result = $method('required|regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]|max_length[10]'); - $this->assertSame('regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]', $result[1]); + $result = $method('required|regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]|max_length[10]'); + $this->assertSame('regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]', $result[1]); } public function testTagReplacement(): void @@ -1365,18 +1365,18 @@ public function provideStringRulesCases(): iterable ]; yield [ - 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric', - ['required', 'regex_match[/^(01[2689]|09)[0-9]{8}$/]', 'numeric'], + 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric', + ['required', 'regex_match[/^(01[2689]|09)\d{8}$/]', 'numeric'], ]; yield [ - 'required|regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]|max_length[10]', - ['required', 'regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]', 'max_length[10]'], + 'required|regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]|max_length[10]', + ['required', 'regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]', 'max_length[10]'], ]; yield [ - 'required|regex_match[/^(01|2689|09)[0-9]{8}$/]|numeric', - ['required', 'regex_match[/^(01|2689|09)[0-9]{8}$/]', 'numeric'], + 'required|regex_match[/^(01|2689|09)\d{8}$/]|numeric', + ['required', 'regex_match[/^(01|2689|09)\d{8}$/]', 'numeric'], ]; } From f171b089a458513354ebf05997f5a11b53308204 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 15 Jun 2023 09:50:44 +0700 Subject: [PATCH 3/4] skip SimplifyRegexPatternRector --- rector.php | 2 ++ system/Database/OCI8/Connection.php | 2 +- system/Helpers/text_helper.php | 2 +- system/Router/RouteCollection.php | 2 +- .../Routes/SampleURIGeneratorTest.php | 2 +- tests/system/Database/Builder/SelectTest.php | 6 ++--- tests/system/Database/RawSqlTest.php | 4 +-- tests/system/Router/RouteCollectionTest.php | 25 +++++++++---------- tests/system/Validation/FormatRulesTest.php | 4 +-- tests/system/Validation/ValidationTest.php | 20 +++++++-------- 10 files changed, 35 insertions(+), 34 deletions(-) diff --git a/rector.php b/rector.php index 2356339cb93b..df51a9b43b5a 100644 --- a/rector.php +++ b/rector.php @@ -112,6 +112,8 @@ GetMockBuilderGetMockToCreateMockRector::class => [ __DIR__ . '/tests/system/Email/EmailTest.php', ], + + SimplifyRegexPatternRector::class, ]); // auto import fully qualified class names diff --git a/system/Database/OCI8/Connection.php b/system/Database/OCI8/Connection.php index ee5b48a8b37a..ce6554ddc63a 100644 --- a/system/Database/OCI8/Connection.php +++ b/system/Database/OCI8/Connection.php @@ -53,7 +53,7 @@ class Connection extends BaseConnection protected $validDSNs = [ 'tns' => '/^\(DESCRIPTION=(\(.+\)){2,}\)$/', // TNS // Easy Connect string (Oracle 10g+) - 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9]\d{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', + 'ec' => '/^(\/\/)?[a-z0-9.:_-]+(:[1-9][0-9]{0,4})?(\/[a-z0-9$_]+)?(:[^\/])?(\/[a-z0-9$_]+)?$/i', 'in' => '/^[a-z0-9$_]+$/i', // Instance name (defined in tnsnames.ora) ]; diff --git a/system/Helpers/text_helper.php b/system/Helpers/text_helper.php index 8f96b423b02b..2343a89bfafe 100755 --- a/system/Helpers/text_helper.php +++ b/system/Helpers/text_helper.php @@ -662,7 +662,7 @@ function _from_random(int $length, string $pool): string */ function increment_string(string $str, string $separator = '_', int $first = 1): string { - preg_match('/(.+)' . preg_quote($separator, '/') . '(\d+)$/', $str, $match); + preg_match('/(.+)' . preg_quote($separator, '/') . '([0-9]+)$/', $str, $match); return isset($match[2]) ? $match[1] . $separator . ((int) $match[2] + 1) : $str . $separator . $first; } diff --git a/system/Router/RouteCollection.php b/system/Router/RouteCollection.php index ab3066f9eff4..66724935e31c 100644 --- a/system/Router/RouteCollection.php +++ b/system/Router/RouteCollection.php @@ -98,7 +98,7 @@ class RouteCollection implements RouteCollectionInterface 'any' => '.*', 'segment' => '[^/]+', 'alphanum' => '[a-zA-Z0-9]+', - 'num' => '\d+', + 'num' => '[0-9]+', 'alpha' => '[a-zA-Z]+', 'hash' => '[^/]+', ]; diff --git a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php index 8c64a72ab198..4b7b8fa3e814 100644 --- a/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php +++ b/tests/system/Commands/Utilities/Routes/SampleURIGeneratorTest.php @@ -38,7 +38,7 @@ public function routeKeyProvider(): Generator { yield from [ 'root' => ['/', '/'], - 'placeholder num' => ['shop/product/(\d+)', 'shop/product/123'], + 'placeholder num' => ['shop/product/([0-9]+)', 'shop/product/123'], 'placeholder segment' => ['shop/product/([^/]+)', 'shop/product/abc_123'], 'placeholder any' => ['shop/product/(.*)', 'shop/product/123/abc'], 'auto route' => ['home/index[/...]', 'home/index/1/2/3/4/5'], diff --git a/tests/system/Database/Builder/SelectTest.php b/tests/system/Database/Builder/SelectTest.php index 5f92d6f5f5ed..af7bf96d119e 100644 --- a/tests/system/Database/Builder/SelectTest.php +++ b/tests/system/Database/Builder/SelectTest.php @@ -105,7 +105,7 @@ public function testSelectWorksWithRawSql() { $builder = new BaseBuilder('users', $this->db); - $sql = 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral'; + $sql = 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral'; $builder->select(new RawSql($sql)); $expected = 'SELECT ' . $sql . ' FROM "users"'; @@ -134,12 +134,12 @@ public function testSelectRegularExpressionWorksWithEscpaeFalse() $builder = new BaseBuilder('ob_human_resources', $this->db); $builder->select( - 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral', + 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral', false ); $expected = <<<'SQL' - SELECT REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral + SELECT REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral FROM "ob_human_resources" SQL; $this->assertSame($expected, $builder->getCompiledSelect()); diff --git a/tests/system/Database/RawSqlTest.php b/tests/system/Database/RawSqlTest.php index b28b0b6ecfea..695a63980e89 100644 --- a/tests/system/Database/RawSqlTest.php +++ b/tests/system/Database/RawSqlTest.php @@ -22,7 +22,7 @@ final class RawSqlTest extends CIUnitTestCase { public function testCanConvertToString() { - $expected = 'REGEXP_SUBSTR(ral_anno,"\d{1,2}([,.]\d{1,3})([,.]\d{1,3})") AS ral'; + $expected = 'REGEXP_SUBSTR(ral_anno,"[0-9]{1,2}([,.][0-9]{1,3})([,.][0-9]{1,3})") AS ral'; $rawSql = new RawSql($expected); $this->assertSame($expected, (string) $rawSql); @@ -47,6 +47,6 @@ public function testGetBindingKey() $key = $rawSql->getBindingKey(); - $this->assertMatchesRegularExpression('/\ARawSql\d+\z/', $key); + $this->assertMatchesRegularExpression('/\ARawSql[0-9]+\z/', $key); } } diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index a37d98f1c6e2..6458449a02c9 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -12,7 +12,6 @@ namespace CodeIgniter\Router; use CodeIgniter\Config\Services; -use CodeIgniter\controller; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; @@ -89,7 +88,7 @@ public function testBasicAddCallableWithParamsString() $routes = $routes->getRoutes(); $expects = [ - 'product/(\d+)/(\d+)' => '\Tests\Support\Controllers\Hello::index/$2/$1', + 'product/([0-9]+)/([0-9]+)' => '\Tests\Support\Controllers\Hello::index/$2/$1', ]; $this->assertSame($expects, $routes); } @@ -102,7 +101,7 @@ public function testBasicAddCallableWithParamsWithoutString() $routes = $routes->getRoutes(); $expects = [ - 'product/(\d+)/(\d+)' => '\Tests\Support\Controllers\Hello::index/$1/$2', + 'product/([0-9]+)/([0-9]+)' => '\Tests\Support\Controllers\Hello::index/$1/$2', ]; $this->assertSame($expects, $routes); } @@ -238,7 +237,7 @@ public function testAddRecognizesCustomNamespaces() $routes->add('home', 'controller'); $expects = [ - 'home' => '\\' . controller::class, + 'home' => '\CodeIgniter\controller', ]; $routes = $routes->getRoutes(); @@ -616,10 +615,10 @@ public function testResourcesWithCustomPlaceholder() $routes->resource('photos', ['placeholder' => ':num']); $expected = [ - 'photos' => '\Photos::index', - 'photos/new' => '\Photos::new', - 'photos/(\d+)/edit' => '\Photos::edit/$1', - 'photos/(\d+)' => '\Photos::show/$1', + 'photos' => '\Photos::index', + 'photos/new' => '\Photos::new', + 'photos/([0-9]+)/edit' => '\Photos::edit/$1', + 'photos/([0-9]+)' => '\Photos::show/$1', ]; $this->assertSame($expected, $routes->getRoutes()); @@ -634,10 +633,10 @@ public function testResourcesWithDefaultPlaceholder() $routes->resource('photos'); $expected = [ - 'photos' => '\Photos::index', - 'photos/new' => '\Photos::new', - 'photos/(\d+)/edit' => '\Photos::edit/$1', - 'photos/(\d+)' => '\Photos::show/$1', + 'photos' => '\Photos::index', + 'photos/new' => '\Photos::new', + 'photos/([0-9]+)/edit' => '\Photos::edit/$1', + 'photos/([0-9]+)' => '\Photos::show/$1', ]; $this->assertSame($expected, $routes->getRoutes()); @@ -1400,7 +1399,7 @@ public function testOffsetParameters() $routes = $this->getCollector(); $routes->get('users/(:num)', 'users/show/$1', ['offset' => 1]); - $expected = ['users/(\d+)' => '\users/show/$2']; + $expected = ['users/([0-9]+)' => '\users/show/$2']; $this->assertSame($expected, $routes->getRoutes()); } diff --git a/tests/system/Validation/FormatRulesTest.php b/tests/system/Validation/FormatRulesTest.php index 856a797f2911..8e78750e494e 100644 --- a/tests/system/Validation/FormatRulesTest.php +++ b/tests/system/Validation/FormatRulesTest.php @@ -63,7 +63,7 @@ public function testRegexMatch(): void $this->validation->setRules([ 'foo' => 'regex_match[/[a-z]/]', - 'phone' => 'regex_match[/^(01[2689]|09)\d{8}$/]', + 'phone' => 'regex_match[/^(01[2689]|09)[0-9]{8}$/]', ]); $this->assertTrue($this->validation->run($data)); @@ -78,7 +78,7 @@ public function testRegexMatchFalse(): void $this->validation->setRules([ 'foo' => 'regex_match[\d]', - 'phone' => 'regex_match[/^(01[2689]|09)\d{8}$/]', + 'phone' => 'regex_match[/^(01[2689]|09)[0-9]{8}$/]', ]); $this->assertFalse($this->validation->run($data)); diff --git a/tests/system/Validation/ValidationTest.php b/tests/system/Validation/ValidationTest.php index 1ca2e8970425..efc00290ebd4 100644 --- a/tests/system/Validation/ValidationTest.php +++ b/tests/system/Validation/ValidationTest.php @@ -883,7 +883,7 @@ public function testHasError(): void public function testSplitRulesTrue(): void { $this->validation->setRules([ - 'phone' => 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric', + 'phone' => 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric', ]); $this->assertTrue($this->validation->run(['phone' => '0987654321'])); } @@ -891,7 +891,7 @@ public function testSplitRulesTrue(): void public function testSplitRulesFalse(): void { $this->validation->setRules([ - 'phone' => 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric', + 'phone' => 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric', ]); $this->assertFalse($this->validation->run(['phone' => '09876543214'])); } @@ -909,8 +909,8 @@ public function testSplitNotRegex(): void public function testSplitRegex(): void { $method = $this->getPrivateMethodInvoker($this->validation, 'splitRules'); - $result = $method('required|regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]|max_length[10]'); - $this->assertSame('regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]', $result[1]); + $result = $method('required|regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]|max_length[10]'); + $this->assertSame('regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]', $result[1]); } public function testTagReplacement(): void @@ -1365,18 +1365,18 @@ public function provideStringRulesCases(): iterable ]; yield [ - 'required|regex_match[/^(01[2689]|09)\d{8}$/]|numeric', - ['required', 'regex_match[/^(01[2689]|09)\d{8}$/]', 'numeric'], + 'required|regex_match[/^(01[2689]|09)[0-9]{8}$/]|numeric', + ['required', 'regex_match[/^(01[2689]|09)[0-9]{8}$/]', 'numeric'], ]; yield [ - 'required|regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]|max_length[10]', - ['required', 'regex_match[/^\d{4}[\-\.\[\/]\d{2}[\-\.\[\/]\d{2}/]', 'max_length[10]'], + 'required|regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]|max_length[10]', + ['required', 'regex_match[/^[0-9]{4}[\-\.\[\/][0-9]{2}[\-\.\[\/][0-9]{2}/]', 'max_length[10]'], ]; yield [ - 'required|regex_match[/^(01|2689|09)\d{8}$/]|numeric', - ['required', 'regex_match[/^(01|2689|09)\d{8}$/]', 'numeric'], + 'required|regex_match[/^(01|2689|09)[0-9]{8}$/]|numeric', + ['required', 'regex_match[/^(01|2689|09)[0-9]{8}$/]', 'numeric'], ]; } From 8967217e6fb727a9b544138144312933626667cb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Thu, 15 Jun 2023 09:52:49 +0700 Subject: [PATCH 4/4] Re-run Rector --- tests/system/Router/RouteCollectionTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/system/Router/RouteCollectionTest.php b/tests/system/Router/RouteCollectionTest.php index 6458449a02c9..40c5da39b091 100644 --- a/tests/system/Router/RouteCollectionTest.php +++ b/tests/system/Router/RouteCollectionTest.php @@ -12,6 +12,7 @@ namespace CodeIgniter\Router; use CodeIgniter\Config\Services; +use CodeIgniter\controller; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Test\CIUnitTestCase; use Config\Modules; @@ -237,7 +238,7 @@ public function testAddRecognizesCustomNamespaces() $routes->add('home', 'controller'); $expects = [ - 'home' => '\CodeIgniter\controller', + 'home' => '\\' . controller::class, ]; $routes = $routes->getRoutes();