Skip to content

Commit f788d46

Browse files
committed
test: remove dynamic property in ControllerTest
1 parent 47ed563 commit f788d46

2 files changed

Lines changed: 32 additions & 13 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* This file is part of CodeIgniter 4 framework.
5+
*
6+
* (c) CodeIgniter Foundation <admin@codeigniter.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*/
11+
12+
namespace Tests\Support\Config;
13+
14+
use Config\Validation as ValidationConfig;
15+
16+
class Validation extends ValidationConfig
17+
{
18+
public $signup = [
19+
'username' => 'required',
20+
];
21+
public $signup_errors = [
22+
'username' => [
23+
'required' => 'You must choose a username.',
24+
],
25+
];
26+
}

tests/system/ControllerTest.php

Lines changed: 6 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;
@@ -21,6 +22,7 @@
2122
use Config\App;
2223
use Config\Services;
2324
use Psr\Log\LoggerInterface;
25+
use Tests\Support\Config\Validation;
2426

2527
/**
2628
* Exercise our core Controller class.
@@ -118,15 +120,8 @@ public function testValidateWithStringRulesNotFound()
118120

119121
public function testValidateWithStringRulesFoundReadMessagesFromValidationConfig()
120122
{
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-
];
123+
$validation = new Validation();
124+
Factories::injectMock('config', 'Validation', $validation);
130125

131126
// make sure we can instantiate one
132127
$this->controller = new Controller();
@@ -139,10 +134,8 @@ public function testValidateWithStringRulesFoundReadMessagesFromValidationConfig
139134

140135
public function testValidateWithStringRulesFoundUseMessagesParameter()
141136
{
142-
$validation = config('Validation');
143-
$validation->signup = [
144-
'username' => 'required',
145-
];
137+
$validation = new Validation();
138+
Factories::injectMock('config', 'Validation', $validation);
146139

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

0 commit comments

Comments
 (0)