From 272bd4b1a7e3049d174a3b355b607732255084ff Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 9 May 2026 17:35:45 +0700 Subject: [PATCH 1/2] chore: use single class per file when possible on tests/ directory --- .../Cache/Handlers/BaseTestFileHandler.php | 64 +++++++++++++++++++ .../system/Cache/Handlers/FileHandlerTest.php | 48 -------------- tests/system/View/DBResultDummy.php | 42 ++++++++++++ tests/system/View/TableTest.php | 27 -------- 4 files changed, 106 insertions(+), 75 deletions(-) create mode 100644 tests/system/Cache/Handlers/BaseTestFileHandler.php create mode 100644 tests/system/View/DBResultDummy.php diff --git a/tests/system/Cache/Handlers/BaseTestFileHandler.php b/tests/system/Cache/Handlers/BaseTestFileHandler.php new file mode 100644 index 000000000000..105d648564b7 --- /dev/null +++ b/tests/system/Cache/Handlers/BaseTestFileHandler.php @@ -0,0 +1,64 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Cache\Handlers; + +use Config\Cache; + +/** + * @internal + */ +final class BaseTestFileHandler extends FileHandler +{ + private static string $directory = 'FileHandler'; + private readonly Cache $config; + + public function __construct() + { + $this->config = new Cache(); + $this->config->file['storePath'] .= self::$directory; + + parent::__construct($this->config); + + helper('filesystem'); + } + + /** + * @return array{ + * name: string, + * server_path: string, + * size: int, + * date: int, + * readable: bool, + * writable: bool, + * executable: bool, + * fileperms: int, + * }|null + */ + public function getFileInfoTest(): ?array + { + $tmpHandle = tmpfile(); + stream_get_meta_data($tmpHandle); + + return get_file_info(stream_get_meta_data($tmpHandle)['uri'], [ + 'name', + 'server_path', + 'size', + 'date', + 'readable', + 'writable', + 'executable', + 'fileperms', + ]); + } +} diff --git a/tests/system/Cache/Handlers/FileHandlerTest.php b/tests/system/Cache/Handlers/FileHandlerTest.php index 16c6042be124..c4fa8481bbd4 100644 --- a/tests/system/Cache/Handlers/FileHandlerTest.php +++ b/tests/system/Cache/Handlers/FileHandlerTest.php @@ -399,51 +399,3 @@ public function testReconnect(): void $this->assertTrue($this->handler->reconnect()); } } - -/** - * @internal - */ -final class BaseTestFileHandler extends FileHandler -{ - private static string $directory = 'FileHandler'; - private readonly Cache $config; - - public function __construct() - { - $this->config = new Cache(); - $this->config->file['storePath'] .= self::$directory; - - parent::__construct($this->config); - - helper('filesystem'); - } - - /** - * @return array{ - * name: string, - * server_path: string, - * size: int, - * date: int, - * readable: bool, - * writable: bool, - * executable: bool, - * fileperms: int, - * }|null - */ - public function getFileInfoTest(): ?array - { - $tmpHandle = tmpfile(); - stream_get_meta_data($tmpHandle); - - return get_file_info(stream_get_meta_data($tmpHandle)['uri'], [ - 'name', - 'server_path', - 'size', - 'date', - 'readable', - 'writable', - 'executable', - 'fileperms', - ]); - } -} diff --git a/tests/system/View/DBResultDummy.php b/tests/system/View/DBResultDummy.php new file mode 100644 index 000000000000..b322969cafff --- /dev/null +++ b/tests/system/View/DBResultDummy.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\View; + +use CodeIgniter\Database\MySQLi\Result; + +// We need this for the _set_from_db_result() test +class DBResultDummy extends Result +{ + public function getFieldNames(): array + { + return [ + 'name', + 'email', + ]; + } + + public function getResultArray(): array + { + return [ + [ + 'name' => 'John Doe', + 'email' => 'john@doe.com', + ], + [ + 'name' => 'Foo Bar', + 'email' => 'foo@bar.com', + ], + ]; + } +} diff --git a/tests/system/View/TableTest.php b/tests/system/View/TableTest.php index 4ce6522fd4af..62df5b02c0b3 100644 --- a/tests/system/View/TableTest.php +++ b/tests/system/View/TableTest.php @@ -13,7 +13,6 @@ namespace CodeIgniter\View; -use CodeIgniter\Database\MySQLi\Result; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\Mock\MockTable; use PHPUnit\Framework\Attributes\DataProvider; @@ -888,29 +887,3 @@ public function testGenerateTableWithHeadingContainFieldNamedData(): void $this->assertStringContainsString('codigo32023-10-16 21:53:25PERCENTUAL10', $generated); } } - -// We need this for the _set_from_db_result() test -class DBResultDummy extends Result -{ - public function getFieldNames(): array - { - return [ - 'name', - 'email', - ]; - } - - public function getResultArray(): array - { - return [ - [ - 'name' => 'John Doe', - 'email' => 'john@doe.com', - ], - [ - 'name' => 'Foo Bar', - 'email' => 'foo@bar.com', - ], - ]; - } -} From 35f0cb3fc915aeb029e3f0b15bf62873757b82d3 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sat, 9 May 2026 17:43:03 +0700 Subject: [PATCH 2/2] chore: add return array iterable doc and regenerate baseline --- tests/system/View/DBResultDummy.php | 3 +++ utils/phpstan-baseline/loader.neon | 2 +- .../phpstan-baseline/missingType.iterableValue.neon | 13 ++++--------- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/tests/system/View/DBResultDummy.php b/tests/system/View/DBResultDummy.php index b322969cafff..fb42f41b04b6 100644 --- a/tests/system/View/DBResultDummy.php +++ b/tests/system/View/DBResultDummy.php @@ -26,6 +26,9 @@ public function getFieldNames(): array ]; } + /** + * @return array> + */ public function getResultArray(): array { return [ diff --git a/utils/phpstan-baseline/loader.neon b/utils/phpstan-baseline/loader.neon index 57d40a379ca7..3ea6e93eca06 100644 --- a/utils/phpstan-baseline/loader.neon +++ b/utils/phpstan-baseline/loader.neon @@ -1,4 +1,4 @@ -# total 2055 errors +# total 2054 errors includes: - argument.type.neon diff --git a/utils/phpstan-baseline/missingType.iterableValue.neon b/utils/phpstan-baseline/missingType.iterableValue.neon index fb692f3ac52f..571912cb7ad4 100644 --- a/utils/phpstan-baseline/missingType.iterableValue.neon +++ b/utils/phpstan-baseline/missingType.iterableValue.neon @@ -1,4 +1,4 @@ -# total 1258 errors +# total 1257 errors parameters: ignoreErrors: @@ -6217,20 +6217,15 @@ parameters: count: 1 path: ../../tests/system/Validation/ValidationTest.php - - - message: '#^Method CodeIgniter\\View\\ParserTest\:\:provideEscHandling\(\) return type has no value type specified in iterable type iterable\.$#' - count: 1 - path: ../../tests/system/View/ParserTest.php - - message: '#^Method CodeIgniter\\View\\DBResultDummy\:\:getFieldNames\(\) return type has no value type specified in iterable type array\.$#' count: 1 - path: ../../tests/system/View/TableTest.php + path: ../../tests/system/View/DBResultDummy.php - - message: '#^Method CodeIgniter\\View\\DBResultDummy\:\:getResultArray\(\) return type has no value type specified in iterable type array\.$#' + message: '#^Method CodeIgniter\\View\\ParserTest\:\:provideEscHandling\(\) return type has no value type specified in iterable type iterable\.$#' count: 1 - path: ../../tests/system/View/TableTest.php + path: ../../tests/system/View/ParserTest.php - message: '#^Method CodeIgniter\\View\\TableTest\:\:orderedColumnUsecases\(\) return type has no value type specified in iterable type iterable\.$#'