Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into 4.4
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed May 14, 2023
2 parents 3089cda + fb0583f commit 3b3cfb5
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 24 deletions.
15 changes: 0 additions & 15 deletions .github/workflows/test-phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
include:
- php-version: '8.2'
composer-option: '--ignore-platform-req=php'

uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
with:
Expand All @@ -73,7 +70,6 @@ jobs:
enable-coverage: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
extra-extensions: imagick, redis, memcached
extra-composer-options: ${{ matrix.composer-option }}

database-live-tests:
needs:
Expand All @@ -100,8 +96,6 @@ jobs:
- php-version: '7.4'
db-platform: MySQLi
mysql-version: '8.0'
- php-version: '8.2'
composer-option: '--ignore-platform-req=php'

uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
with:
Expand All @@ -115,7 +109,6 @@ jobs:
enable-coverage: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
extra-extensions: mysqli, oci8, pgsql, sqlsrv-5.10.1, sqlite3
extra-composer-options: ${{ matrix.composer-option }}

separate-process-tests:
needs:
Expand All @@ -129,9 +122,6 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
include:
- php-version: '8.2'
composer-option: '--ignore-platform-req=php'

uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
with:
Expand All @@ -143,7 +133,6 @@ jobs:
enable-coverage: true # needs xdebug for assertHeaderEmitted() tests
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
extra-extensions: mysqli, oci8, pgsql, sqlsrv-5.10.1, sqlite3
extra-composer-options: ${{ matrix.composer-option }}

cache-live-tests:
needs:
Expand All @@ -157,9 +146,6 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
include:
- php-version: '8.2'
composer-option: '--ignore-platform-req=php'

uses: ./.github/workflows/reusable-phpunit-test.yml # @TODO Extract to codeigniter4/.github repo
with:
Expand All @@ -171,7 +157,6 @@ jobs:
enable-coverage: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
enable-profiling: ${{ matrix.php-version == needs.coverage-php-version.outputs.version }}
extra-extensions: redis, memcached
extra-composer-options: ${{ matrix.composer-option }}

coveralls:
name: Upload coverage results to Coveralls
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"phpunit/phpcov": "^8.2",
"phpunit/phpunit": "^9.1",
"predis/predis": "^1.1 || ^2.0",
"rector/rector": "0.15.25",
"rector/rector": "0.16.0",
"vimeo/psalm": "^5.0"
},
"suggest": {
Expand Down
4 changes: 0 additions & 4 deletions system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@

use CodeIgniter\Format\FormatterInterface;
use CodeIgniter\HTTP\IncomingRequest;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Config\Services;

/**
* Provides common, more readable, methods to provide
* consistent HTTP responses under a variety of common
* situations when working as an API.
*
* @property RequestInterface $request
* @property ResponseInterface $response
*/
trait ResponseTrait
{
Expand Down
2 changes: 1 addition & 1 deletion system/Filters/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public function enableFilters(array $names, string $when = 'before')
/**
* Returns the arguments for a specified key, or all.
*
* @return mixed
* @return array<string, string>|string
*/
public function getArguments(?string $key = null)
{
Expand Down
6 changes: 3 additions & 3 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ protected function processRules(
}

// Otherwise remove the if_exist rule and continue the process
$rules = array_diff($rules, ['if_exist']);
$rules = array_filter($rules, static fn ($rule) => $rule instanceof Closure || $rule !== 'if_exist');
}

if (in_array('permit_empty', $rules, true)) {
Expand All @@ -281,7 +281,7 @@ protected function processRules(
$passed = true;

foreach ($rules as $rule) {
if (preg_match('/(.*?)\[(.*)\]/', $rule, $match)) {
if (! $this->isClosure($rule) && preg_match('/(.*?)\[(.*)\]/', $rule, $match)) {
$rule = $match[1];
$param = $match[2];

Expand All @@ -306,7 +306,7 @@ protected function processRules(
}
}

$rules = array_diff($rules, ['permit_empty']);
$rules = array_filter($rules, static fn ($rule) => $rule instanceof Closure || $rule !== 'permit_empty');
}

foreach ($rules as $i => $rule) {
Expand Down
12 changes: 12 additions & 0 deletions tests/system/Validation/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ public function ifExistProvider(): Generator
['foo' => []],
true,
],
// Testing with closure
[
['foo' => ['if_exist', static fn ($value) => true]],
['foo' => []],
true,
],
];
}

Expand Down Expand Up @@ -275,6 +281,12 @@ public function providePermitEmptyCases(): Generator
['foo' => '', 'bar' => 1],
true,
],
// Testing with closure
[
['foo' => ['permit_empty', static fn ($value) => true]],
['foo' => ''],
true,
],
];
}

Expand Down
6 changes: 6 additions & 0 deletions tests/system/Validation/StrictRules/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ public function providePermitEmptyCasesStrict(): Generator
['foo' => false],
true,
],
// Testing with closure
[
['foo' => ['permit_empty', static fn ($value) => true]],
['foo' => ''],
true,
],
];
}

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.3.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Deprecations
Bugs Fixed
**********

- **Validation:** Fixed a bug where a closure used in combination with ``permit_empty`` or ``if_exist`` rules was causing an error.

See the repo's
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_
for a complete list of bugs fixed.

0 comments on commit 3b3cfb5

Please sign in to comment.