Skip to content

Commit 5e3de7d

Browse files
authored
Merge pull request #8307 from kenjis/refactor-tests-support
test: refactor files in `tests/_support/` by rector
2 parents c185910 + 797c5d6 commit 5e3de7d

32 files changed

+123
-85
lines changed

rector.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@
8080
__DIR__ . '/system/ThirdParty',
8181
__DIR__ . '/tests/system/Config/fixtures',
8282
__DIR__ . '/tests/system/Filters/fixtures',
83-
__DIR__ . '/tests/_support',
83+
__DIR__ . '/tests/_support/Commands/Foobar.php',
84+
__DIR__ . '/tests/_support/View',
85+
8486
JsonThrowOnErrorRector::class,
8587
YieldDataProviderRector::class,
8688

8789
RemoveUnusedPrivateMethodRector::class => [
8890
// private method called via getPrivateMethodInvoker
8991
__DIR__ . '/tests/system/Test/ReflectionHelperTest.php',
92+
__DIR__ . '/tests/_support/Test/TestForReflectionHelper.php',
9093
],
9194

9295
RemoveUnusedConstructorParamRector::class => [

tests/_support/Config/Filters.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313

1414
namespace Tests\Support\Config\Filters;
1515

16+
use Tests\Support\Filters\Customfilter;
17+
use Tests\Support\Filters\RedirectFilter;
18+
1619
/**
1720
* @psalm-suppress UndefinedGlobalVariable
1821
*/
19-
$filters->aliases['test-customfilter'] = \Tests\Support\Filters\Customfilter::class;
20-
$filters->aliases['test-redirectfilter'] = \Tests\Support\Filters\RedirectFilter::class;
22+
$filters->aliases['test-customfilter'] = Customfilter::class;
23+
$filters->aliases['test-redirectfilter'] = RedirectFilter::class;

tests/_support/Config/Registrar.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,8 @@ public static function Database()
134134

135135
// Under GitHub Actions, we can set an ENV var named 'DB'
136136
// so that we can test against multiple databases.
137-
if ($group = getenv('DB')) {
138-
if (! empty(self::$dbConfig[$group])) {
139-
$config['tests'] = self::$dbConfig[$group];
140-
}
137+
if (($group = getenv('DB')) && ! empty(self::$dbConfig[$group])) {
138+
$config['tests'] = self::$dbConfig[$group];
141139
}
142140

143141
return $config;

tests/_support/Database/Migrations/20160428212500_Create_test_tables.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function up(): void
5151
// missing types :
5252
// TINYINT,MEDIUMINT,BIT,YEAR,BINARY , VARBINARY, TINYTEXT,LONGTEXT,YEAR,JSON,Spatial data types
5353
// id must be interger else SQLite3 error on not null for autoinc field
54-
$data_type_fields = [
54+
$dataTypeFields = [
5555
'id' => ['type' => 'INTEGER', 'constraint' => 20, 'auto_increment' => true],
5656
'type_varchar' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
5757
'type_char' => ['type' => 'CHAR', 'constraint' => 10, 'null' => true],
@@ -77,26 +77,26 @@ public function up(): void
7777

7878
if ($this->db->DBDriver === 'Postgre') {
7979
unset(
80-
$data_type_fields['type_real'],
81-
$data_type_fields['type_decimal']
80+
$dataTypeFields['type_real'],
81+
$dataTypeFields['type_decimal']
8282
);
8383
}
8484

8585
if ($this->db->DBDriver === 'SQLSRV') {
86-
unset($data_type_fields['type_timestamp']);
86+
unset($dataTypeFields['type_timestamp']);
8787
}
8888

8989
if ($this->db->DBDriver === 'Postgre' || $this->db->DBDriver === 'SQLSRV') {
9090
unset(
91-
$data_type_fields['type_enum'],
92-
$data_type_fields['type_set'],
93-
$data_type_fields['type_mediumtext'],
94-
$data_type_fields['type_double'],
95-
$data_type_fields['type_blob']
91+
$dataTypeFields['type_enum'],
92+
$dataTypeFields['type_set'],
93+
$dataTypeFields['type_mediumtext'],
94+
$dataTypeFields['type_double'],
95+
$dataTypeFields['type_blob']
9696
);
9797
}
9898

99-
$this->forge->addField($data_type_fields)->addKey('id', true)->createTable('type_test', true);
99+
$this->forge->addField($dataTypeFields)->addKey('id', true)->createTable('type_test', true);
100100

101101
// Empty Table
102102
$this->forge->addField([

tests/_support/Database/Seeds/CITestSeeder.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function run(): void
107107
'type_time' => '2020-07-18T15:22:00.000+02:00',
108108
'type_datetime' => '2020-06-18T05:12:24.000+02:00',
109109
'type_timestamp' => '2019-07-18T21:53:21.000+02:00',
110-
'type_bigint' => 2342342,
110+
'type_bigint' => 2_342_342,
111111
'type_boolean' => 1,
112112
],
113113
],
@@ -178,11 +178,11 @@ public function run(): void
178178
unset($data['type_test'][0]['type_blob']);
179179
}
180180

181-
foreach ($data as $table => $dummy_data) {
181+
foreach ($data as $table => $dummyData) {
182182
$this->db->table($table)->truncate();
183183

184-
foreach ($dummy_data as $single_dummy_data) {
185-
$this->db->table($table)->insert($single_dummy_data);
184+
foreach ($dummyData as $singleDummyData) {
185+
$this->db->table($table)->insert($singleDummyData);
186186
}
187187
}
188188
}

tests/_support/Entity/Cast/CastBinaryUUID.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* This file is part of CodeIgniter 4 framework.
57
*

tests/_support/Entity/UUID.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
/**
46
* This file is part of CodeIgniter 4 framework.
57
*

tests/_support/Filters/Customfilter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
namespace Tests\Support\Filters;
1515

16+
use CodeIgniter\Filters\FilterInterface;
1617
use CodeIgniter\HTTP\RequestInterface;
1718
use CodeIgniter\HTTP\ResponseInterface;
1819

19-
class Customfilter implements \CodeIgniter\Filters\FilterInterface
20+
class Customfilter implements FilterInterface
2021
{
2122
public function before(RequestInterface $request, $arguments = null)
2223
{

tests/_support/Filters/RedirectFilter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313

1414
namespace Tests\Support\Filters;
1515

16+
use CodeIgniter\Filters\FilterInterface;
1617
use CodeIgniter\HTTP\RequestInterface;
1718
use CodeIgniter\HTTP\ResponseInterface;
1819

19-
class RedirectFilter implements \CodeIgniter\Filters\FilterInterface
20+
class RedirectFilter implements FilterInterface
2021
{
2122
public function before(RequestInterface $request, $arguments = null)
2223
{

tests/_support/Log/Handlers/TestHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
namespace Tests\Support\Log\Handlers;
1515

16+
use CodeIgniter\Log\Handlers\FileHandler;
17+
1618
/**
1719
* Class TestHandler
1820
*
1921
* A simple LogHandler that stores the logs in memory.
2022
* Only used for testing purposes.
2123
*/
22-
class TestHandler extends \CodeIgniter\Log\Handlers\FileHandler
24+
class TestHandler extends FileHandler
2325
{
2426
/**
2527
* Local storage for logs.

0 commit comments

Comments
 (0)