Skip to content

Commit 272bd4b

Browse files
committed
chore: use single class per file when possible on tests/ directory
1 parent 661af8c commit 272bd4b

4 files changed

Lines changed: 106 additions & 75 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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
public function getResultArray(): array
30+
{
31+
return [
32+
[
33+
'name' => 'John Doe',
34+
'email' => 'john@doe.com',
35+
],
36+
[
37+
'name' => 'Foo Bar',
38+
'email' => 'foo@bar.com',
39+
],
40+
];
41+
}
42+
}

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-
}

0 commit comments

Comments
 (0)