Skip to content

Commit c3e2582

Browse files
authored
Merge pull request #6587 from kenjis/fix-test-dynamic-properties
test: remove dynamic properties
2 parents e613ea6 + f5069f0 commit c3e2582

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

tests/_support/Log/Handlers/TestHandler.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ class TestHandler extends \CodeIgniter\Log\Handlers\FileHandler
2626
*/
2727
protected static $logs = [];
2828

29+
protected string $destination;
30+
2931
/**
3032
* Where would the log be written?
3133
*/
3234
public function __construct(array $config)
3335
{
3436
parent::__construct($config);
37+
3538
$this->handles = $config['handles'] ?? [];
3639
$this->destination = $this->path . 'log-' . date('Y-m-d') . '.' . $this->fileExtension;
3740

tests/system/Config/FactoriesTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,9 @@ public function testSetsOptions()
7575
public function testUsesConfigOptions()
7676
{
7777
// Simulate having a $widgets property in App\Config\Factory
78-
$config = new Factory();
79-
$config->widgets = ['bar' => 'bam'];
78+
$config = new class () extends Factory {
79+
public $widgets = ['bar' => 'bam'];
80+
};
8081
Factories::injectMock('config', Factory::class, $config);
8182

8283
$result = Factories::getOptions('widgets');

tests/system/ControllerTest.php

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter;
1313

14+
use CodeIgniter\Config\Factories;
1415
use CodeIgniter\HTTP\IncomingRequest;
1516
use CodeIgniter\HTTP\Request;
1617
use CodeIgniter\HTTP\Response;
@@ -20,7 +21,9 @@
2021
use CodeIgniter\Validation\Exceptions\ValidationException;
2122
use Config\App;
2223
use Config\Services;
24+
use Config\Validation as ValidationConfig;
2325
use Psr\Log\LoggerInterface;
26+
use Tests\Support\Config\Validation;
2427

2528
/**
2629
* Exercise our core Controller class.
@@ -118,15 +121,17 @@ public function testValidateWithStringRulesNotFound()
118121

119122
public function testValidateWithStringRulesFoundReadMessagesFromValidationConfig()
120123
{
121-
$validation = config('Validation');
122-
$validation->signup = [
123-
'username' => 'required',
124-
];
125-
$validation->signup_errors = [
126-
'username' => [
127-
'required' => 'You must choose a username.',
128-
],
129-
];
124+
$validation = new class () extends ValidationConfig {
125+
public $signup = [
126+
'username' => 'required',
127+
];
128+
public $signup_errors = [
129+
'username' => [
130+
'required' => 'You must choose a username.',
131+
],
132+
];
133+
};
134+
Factories::injectMock('config', 'Validation', $validation);
130135

131136
// make sure we can instantiate one
132137
$this->controller = new Controller();
@@ -139,10 +144,12 @@ public function testValidateWithStringRulesFoundReadMessagesFromValidationConfig
139144

140145
public function testValidateWithStringRulesFoundUseMessagesParameter()
141146
{
142-
$validation = config('Validation');
143-
$validation->signup = [
144-
'username' => 'required',
145-
];
147+
$validation = new class () extends ValidationConfig {
148+
public $signup = [
149+
'username' => 'required',
150+
];
151+
};
152+
Factories::injectMock('config', 'Validation', $validation);
146153

147154
// make sure we can instantiate one
148155
$this->controller = new Controller();

0 commit comments

Comments
 (0)