mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #6669 from kenjis/fix-tests-dynamic-properties
test: fix dynamic properties
This commit is contained in:
commit
d356d3b477
@ -23,6 +23,8 @@ use Psr\Log\LoggerInterface;
|
||||
*/
|
||||
class SampleClassWithInitController
|
||||
{
|
||||
private ResponseInterface $response;
|
||||
|
||||
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
||||
{
|
||||
$this->response = $response;
|
||||
|
@ -71,10 +71,6 @@ final class GeneralModelTest extends CIUnitTestCase
|
||||
$this->assertFalse(isset($this->model->foobar));
|
||||
$this->assertNull($this->model->foobar);
|
||||
|
||||
$this->model->flavor = 'chocolate';
|
||||
$this->assertTrue(isset($this->model->flavor));
|
||||
$this->assertSame('chocolate', $this->model->flavor);
|
||||
|
||||
// from DB
|
||||
$this->assertTrue(isset($this->model->DBPrefix));
|
||||
$this->assertSame('utf8', $this->model->charset);
|
||||
|
@ -238,26 +238,25 @@ final class ValidationModelTest extends LiveModelTestCase
|
||||
|
||||
public function testValidationWithGroupName(): void
|
||||
{
|
||||
$config = new Validation();
|
||||
$config = new class () extends Validation {
|
||||
public $grouptest = [
|
||||
'name' => [
|
||||
'required',
|
||||
'min_length[3]',
|
||||
],
|
||||
'token' => 'in_list[{id}]',
|
||||
];
|
||||
};
|
||||
Factories::injectMock('config', 'Validation', $config);
|
||||
|
||||
$config->grouptest = [
|
||||
'name' => [
|
||||
'required',
|
||||
'min_length[3]',
|
||||
],
|
||||
'token' => 'in_list[{id}]',
|
||||
];
|
||||
$this->createModel(ValidModel::class);
|
||||
$this->setPrivateProperty($this->model, 'validationRules', 'grouptest');
|
||||
|
||||
$data = [
|
||||
'name' => 'abc',
|
||||
'id' => 13,
|
||||
'token' => 13,
|
||||
];
|
||||
|
||||
Factories::injectMock('config', 'Validation', $config);
|
||||
|
||||
$this->createModel(ValidModel::class);
|
||||
$this->setPrivateProperty($this->model, 'validationRules', 'grouptest');
|
||||
$this->assertTrue($this->model->validate($data));
|
||||
}
|
||||
|
||||
|
@ -249,6 +249,9 @@ final class CellTest extends CIUnitTestCase
|
||||
|
||||
public function testCallInitControllerIfMethodExists()
|
||||
{
|
||||
$this->assertSame(Response::class, $this->cell->render('\Tests\Support\View\SampleClassWithInitController::index'));
|
||||
$this->assertSame(
|
||||
Response::class,
|
||||
$this->cell->render('\Tests\Support\View\SampleClassWithInitController::index')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user