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

+4-1
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

+5-2
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

+2-4
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

+10-10
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

+4-4
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

+2
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

+2
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

+2-1
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

+2-1
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

+3-1
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.

tests/_support/MigrationTestMigrations/Database/Migrations/2018-01-24-102301_Some_migration.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace Tests\Support\MigrationTestMigrations\Database\Migrations;
1515

16-
class Migration_some_migration extends \CodeIgniter\Database\Migration
16+
use CodeIgniter\Database\Migration;
17+
18+
class Migration_some_migration extends Migration
1719
{
1820
public function up(): void
1921
{

tests/_support/MigrationTestMigrations/Database/Migrations/2018-01-24-102302_Another_migration.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
namespace Tests\Support\MigrationTestMigrations\Database\Migrations;
1515

16-
class Migration_another_migration extends \CodeIgniter\Database\Migration
16+
use CodeIgniter\Database\Migration;
17+
18+
class Migration_another_migration extends Migration
1719
{
1820
public function up(): void
1921
{

tests/_support/Models/EntityModel.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
class EntityModel extends Model
1919
{
2020
protected $table = 'job';
21-
protected $returnType = '\Tests\Support\Models\SimpleEntity';
21+
protected $returnType = '\\' . SimpleEntity::class;
2222
protected $useSoftDeletes = false;
2323
protected $dateFormat = 'int';
2424
protected $deletedField = 'deleted_at';

tests/_support/Models/UUIDPkeyModel.php

+2
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/Models/UserObjModel.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace Tests\Support\Models;
1515

1616
use CodeIgniter\Model;
17+
use Tests\Support\Entity\User;
1718

1819
class UserObjModel extends Model
1920
{
@@ -24,7 +25,7 @@ class UserObjModel extends Model
2425
'country',
2526
'deleted_at',
2627
];
27-
protected $returnType = \Tests\Support\Entity\User::class;
28+
protected $returnType = User::class;
2829
protected $useSoftDeletes = true;
2930
protected $dateFormat = 'datetime';
3031
}

tests/_support/Models/UserTimestampModel.php

+2
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/Publishers/TestPublisher.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@ final class TestPublisher extends Publisher
1919
{
2020
/**
2121
* Return value for publish()
22-
*
23-
* @var bool
2422
*/
25-
private static $result = true;
23+
private static bool $result = true;
2624

2725
/**
2826
* Base path to use for the source.

tests/_support/Services/Translation/TranslationNested/TranslationFour.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ class TranslationFour
1717
{
1818
public function list()
1919
{
20-
$translationOne1 = lang('TranslationOne.title');
21-
$translationOne5 = lang('TranslationOne.last_operation_success');
20+
lang('TranslationOne.title');
21+
lang('TranslationOne.last_operation_success');
2222

23-
$translationThree1 = lang('TranslationThree.alerts.created');
24-
$translationThree2 = lang('TranslationThree.alerts.failed_insert');
23+
lang('TranslationThree.alerts.created');
24+
lang('TranslationThree.alerts.failed_insert');
2525

26-
$translationThree5 = lang('TranslationThree.formFields.new.name');
27-
$translationThree7 = lang('TranslationThree.formFields.new.short_tag');
26+
lang('TranslationThree.formFields.new.name');
27+
lang('TranslationThree.formFields.new.short_tag');
2828

29-
$translationFour1 = lang('Translation-Four.dashed.key-with-dash');
30-
$translationFour2 = lang('Translation-Four.dashed.key-with-dash-two');
29+
lang('Translation-Four.dashed.key-with-dash');
30+
lang('Translation-Four.dashed.key-with-dash-two');
3131
}
3232
}

tests/_support/Services/Translation/TranslationOne.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ class TranslationOne
1717
{
1818
public function list()
1919
{
20-
$translationOne1 = lang('TranslationOne.title');
21-
$translationOne2 = lang('TranslationOne.DESCRIPTION');
22-
$translationOne3 = lang('TranslationOne.metaTags');
23-
$translationOne4 = lang('TranslationOne.Copyright');
24-
$translationOne5 = lang('TranslationOne.last_operation_success');
20+
lang('TranslationOne.title');
21+
lang('TranslationOne.DESCRIPTION');
22+
lang('TranslationOne.metaTags');
23+
lang('TranslationOne.Copyright');
24+
lang('TranslationOne.last_operation_success');
2525

26-
$translationThree1 = lang('TranslationThree.alerts.created');
27-
$translationThree2 = lang('TranslationThree.alerts.failed_insert');
28-
$translationThree3 = lang('TranslationThree.alerts.Updated');
29-
$translationThree4 = lang('TranslationThree.alerts.DELETED');
26+
lang('TranslationThree.alerts.created');
27+
lang('TranslationThree.alerts.failed_insert');
28+
lang('TranslationThree.alerts.Updated');
29+
lang('TranslationThree.alerts.DELETED');
3030

31-
$translationThree5 = lang('TranslationThree.formFields.new.name');
32-
$translationThree6 = lang('TranslationThree.formFields.new.TEXT');
33-
$translationThree7 = lang('TranslationThree.formFields.new.short_tag');
34-
$translationThree8 = lang('TranslationThree.formFields.edit.name');
35-
$translationThree9 = lang('TranslationThree.formFields.edit.TEXT');
36-
$translationThree10 = lang('TranslationThree.formFields.edit.short_tag');
31+
lang('TranslationThree.formFields.new.name');
32+
lang('TranslationThree.formFields.new.TEXT');
33+
lang('TranslationThree.formFields.new.short_tag');
34+
lang('TranslationThree.formFields.edit.name');
35+
lang('TranslationThree.formFields.edit.TEXT');
36+
lang('TranslationThree.formFields.edit.short_tag');
3737
}
3838
}

tests/_support/Services/Translation/TranslationThree.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ class TranslationThree
1717
{
1818
public function list()
1919
{
20-
$translationOne1 = lang('TranslationOne.title');
21-
$translationOne2 = lang('TranslationOne.DESCRIPTION');
22-
$translationOne6 = lang('TranslationOne.subTitle');
23-
$translationOne7 = lang('TranslationOne.overflow_style');
20+
lang('TranslationOne.title');
21+
lang('TranslationOne.DESCRIPTION');
22+
lang('TranslationOne.subTitle');
23+
lang('TranslationOne.overflow_style');
2424

25-
$translationThree1 = lang('TranslationThree.alerts.created');
26-
$translationThree2 = lang('TranslationThree.alerts.failed_insert');
25+
lang('TranslationThree.alerts.created');
26+
lang('TranslationThree.alerts.failed_insert');
2727

28-
$translationThree5 = lang('TranslationThree.formFields.new.name');
29-
$translationThree6 = lang('TranslationThree.formFields.new.TEXT');
30-
$translationThree7 = lang('TranslationThree.formFields.new.short_tag');
28+
lang('TranslationThree.formFields.new.name');
29+
lang('TranslationThree.formFields.new.TEXT');
30+
lang('TranslationThree.formFields.new.short_tag');
3131

32-
$translationThree11 = lang('TranslationThree.alerts.CANCELED');
33-
$translationThree12 = lang('TranslationThree.alerts.missing_keys');
32+
lang('TranslationThree.alerts.CANCELED');
33+
lang('TranslationThree.alerts.missing_keys');
3434

35-
$translationThree13 = lang('TranslationThree.formErrors.edit.empty_name');
36-
$translationThree14 = lang('TranslationThree.formErrors.edit.INVALID_TEXT');
37-
$translationThree15 = lang('TranslationThree.formErrors.edit.missing_short_tag');
35+
lang('TranslationThree.formErrors.edit.empty_name');
36+
lang('TranslationThree.formErrors.edit.INVALID_TEXT');
37+
lang('TranslationThree.formErrors.edit.missing_short_tag');
3838
}
3939
}

tests/_support/Services/Translation/TranslationTwo.php

+14-17
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,21 @@ class TranslationTwo
1717
{
1818
public function list()
1919
{
20-
$langKey = 'TranslationTwo.error_key';
21-
2220
// Error language keys
23-
$translationError1 = lang('TranslationTwo');
24-
$translationError2 = lang(' ');
25-
$translationError3 = lang('');
26-
$translationError4 = lang('.invalid_key');
27-
$translationError5 = lang('TranslationTwo.');
28-
$translationError6 = lang('TranslationTwo...');
29-
$translationError7 = lang('..invalid_nested_key..');
30-
31-
$copyTranslationError1 = lang('TranslationTwo');
32-
$copyTranslationError2 = lang(' ');
33-
$copyTranslationError3 = lang('');
34-
$copyTranslationError4 = lang('.invalid_key');
35-
$copyTranslationError5 = lang('TranslationTwo.');
36-
$copyTranslationError6 = lang('TranslationTwo...');
37-
$copyTranslationError7 = lang('..invalid_nested_key..');
21+
lang('TranslationTwo');
22+
lang(' ');
23+
lang('');
24+
lang('.invalid_key');
25+
lang('TranslationTwo.');
26+
lang('TranslationTwo...');
27+
lang('..invalid_nested_key..');
28+
lang('TranslationTwo');
29+
lang(' ');
30+
lang('');
31+
lang('.invalid_key');
32+
lang('TranslationTwo.');
33+
lang('TranslationTwo...');
34+
lang('..invalid_nested_key..');
3835
// Empty in comments lang('') lang(' ')
3936
}
4037
}

tests/_support/Test/TestForReflectionHelper.php

+2
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
*

0 commit comments

Comments
 (0)