Skip to content

Commit 7446d0b

Browse files
authored
Merge pull request #10176 from samsonasik/chore-use-single-class-per-file
chore: use single class per file when possible on tests/ directory
2 parents 661af8c + 35f0cb3 commit 7446d0b

6 files changed

Lines changed: 114 additions & 85 deletions

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace CodeIgniter\Cache\Handlers;
15+
16+
use Config\Cache;
17+
18+
/**
19+
* @internal
20+
*/
21+
final class BaseTestFileHandler extends FileHandler
22+
{
23+
private static string $directory = 'FileHandler';
24+
private readonly Cache $config;
25+
26+
public function __construct()
27+
{
28+
$this->config = new Cache();
29+
$this->config->file['storePath'] .= self::$directory;
30+
31+
parent::__construct($this->config);
32+
33+
helper('filesystem');
34+
}
35+
36+
/**
37+
* @return array{
38+
* name: string,
39+
* server_path: string,
40+
* size: int,
41+
* date: int,
42+
* readable: bool,
43+
* writable: bool,
44+
* executable: bool,
45+
* fileperms: int,
46+
* }|null
47+
*/
48+
public function getFileInfoTest(): ?array
49+
{
50+
$tmpHandle = tmpfile();
51+
stream_get_meta_data($tmpHandle);
52+
53+
return get_file_info(stream_get_meta_data($tmpHandle)['uri'], [
54+
'name',
55+
'server_path',
56+
'size',
57+
'date',
58+
'readable',
59+
'writable',
60+
'executable',
61+
'fileperms',
62+
]);
63+
}
64+
}

tests/system/Cache/Handlers/FileHandlerTest.php

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -399,51 +399,3 @@ public function testReconnect(): void
399399
$this->assertTrue($this->handler->reconnect());
400400
}
401401
}
402-
403-
/**
404-
* @internal
405-
*/
406-
final class BaseTestFileHandler extends FileHandler
407-
{
408-
private static string $directory = 'FileHandler';
409-
private readonly Cache $config;
410-
411-
public function __construct()
412-
{
413-
$this->config = new Cache();
414-
$this->config->file['storePath'] .= self::$directory;
415-
416-
parent::__construct($this->config);
417-
418-
helper('filesystem');
419-
}
420-
421-
/**
422-
* @return array{
423-
* name: string,
424-
* server_path: string,
425-
* size: int,
426-
* date: int,
427-
* readable: bool,
428-
* writable: bool,
429-
* executable: bool,
430-
* fileperms: int,
431-
* }|null
432-
*/
433-
public function getFileInfoTest(): ?array
434-
{
435-
$tmpHandle = tmpfile();
436-
stream_get_meta_data($tmpHandle);
437-
438-
return get_file_info(stream_get_meta_data($tmpHandle)['uri'], [
439-
'name',
440-
'server_path',
441-
'size',
442-
'date',
443-
'readable',
444-
'writable',
445-
'executable',
446-
'fileperms',
447-
]);
448-
}
449-
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of CodeIgniter 4 framework.
7+
*
8+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*/
13+
14+
namespace CodeIgniter\View;
15+
16+
use CodeIgniter\Database\MySQLi\Result;
17+
18+
// We need this for the _set_from_db_result() test
19+
class DBResultDummy extends Result
20+
{
21+
public function getFieldNames(): array
22+
{
23+
return [
24+
'name',
25+
'email',
26+
];
27+
}
28+
29+
/**
30+
* @return array<int, array<string, string>>
31+
*/
32+
public function getResultArray(): array
33+
{
34+
return [
35+
[
36+
'name' => 'John Doe',
37+
'email' => 'john@doe.com',
38+
],
39+
[
40+
'name' => 'Foo Bar',
41+
'email' => 'foo@bar.com',
42+
],
43+
];
44+
}
45+
}

tests/system/View/TableTest.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
namespace CodeIgniter\View;
1515

16-
use CodeIgniter\Database\MySQLi\Result;
1716
use CodeIgniter\Test\CIUnitTestCase;
1817
use CodeIgniter\Test\Mock\MockTable;
1918
use PHPUnit\Framework\Attributes\DataProvider;
@@ -888,29 +887,3 @@ public function testGenerateTableWithHeadingContainFieldNamedData(): void
888887
$this->assertStringContainsString('<td>codigo3</td><td>2023-10-16 21:53:25</td><td>PERCENTUAL</td><td>10</td>', $generated);
889888
}
890889
}
891-
892-
// We need this for the _set_from_db_result() test
893-
class DBResultDummy extends Result
894-
{
895-
public function getFieldNames(): array
896-
{
897-
return [
898-
'name',
899-
'email',
900-
];
901-
}
902-
903-
public function getResultArray(): array
904-
{
905-
return [
906-
[
907-
'name' => 'John Doe',
908-
'email' => 'john@doe.com',
909-
],
910-
[
911-
'name' => 'Foo Bar',
912-
'email' => 'foo@bar.com',
913-
],
914-
];
915-
}
916-
}

utils/phpstan-baseline/loader.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 2055 errors
1+
# total 2054 errors
22

33
includes:
44
- argument.type.neon

utils/phpstan-baseline/missingType.iterableValue.neon

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# total 1258 errors
1+
# total 1257 errors
22

33
parameters:
44
ignoreErrors:
@@ -6217,20 +6217,15 @@ parameters:
62176217
count: 1
62186218
path: ../../tests/system/Validation/ValidationTest.php
62196219

6220-
-
6221-
message: '#^Method CodeIgniter\\View\\ParserTest\:\:provideEscHandling\(\) return type has no value type specified in iterable type iterable\.$#'
6222-
count: 1
6223-
path: ../../tests/system/View/ParserTest.php
6224-
62256220
-
62266221
message: '#^Method CodeIgniter\\View\\DBResultDummy\:\:getFieldNames\(\) return type has no value type specified in iterable type array\.$#'
62276222
count: 1
6228-
path: ../../tests/system/View/TableTest.php
6223+
path: ../../tests/system/View/DBResultDummy.php
62296224

62306225
-
6231-
message: '#^Method CodeIgniter\\View\\DBResultDummy\:\:getResultArray\(\) return type has no value type specified in iterable type array\.$#'
6226+
message: '#^Method CodeIgniter\\View\\ParserTest\:\:provideEscHandling\(\) return type has no value type specified in iterable type iterable\.$#'
62326227
count: 1
6233-
path: ../../tests/system/View/TableTest.php
6228+
path: ../../tests/system/View/ParserTest.php
62346229

62356230
-
62366231
message: '#^Method CodeIgniter\\View\\TableTest\:\:orderedColumnUsecases\(\) return type has no value type specified in iterable type iterable\.$#'

0 commit comments

Comments
 (0)