Answer the question
In order to leave comments, you need to log in
Why is this strange behavior happening when testing Codeception?
The application is written in Yii2. There is a model inherited from the yii\base\Model class , which contains several AR models. Below is the model code.
class InquiryForm extends \yii\base\Model
{
/**
* @var ActiveRecord Адрес регистрации клиента
*/
public $regAddress;
/**
* @var ActiveRecord Анкета
*/
public $inquiry;
/**
* @inheritdoc
*/
public function load($data, $formName = null)
{
$load = [
'inquiry' => $this->inquiry,
'regAddress' => $this->regAddress,
];
$success = false;
foreach ($load as $name => $form) {
$success = $form->load($data, $formName !== '' ? null : $name);
}
return $success;
}
}
protected function _before()
{
$this->_address = $this->createFormMock(Address::class,
[
'field1',
'field2',
'field3',
'field4',
'field5',
'field6'
]
);
$this->_inquiry = $this->createFormMock(InquiryLogical::class,
[
'field1',
'field2',
'field3',
'field4',
'field5',
'field6'
]
);
}
protected function createFormMock(string $class, array $attributes)
{
$mockObject = $this->getMockBuilder($class)
->setMethods(['save', 'attributes'])
->getMock();
$mockObject->method('save')->willReturn(true);
$mockObject->method('attributes')->willReturn($attributes);
return $mockObject;
}
public function testLoadForm()
{
$data = [
'there is some data from $_POST'
];
$form = new InquiryForm(['inquiry' => $this->_inquiry, 'regAddress' => $this->_address]);
$this->assertTrue($form->load($data));
}
$load = [
'inquiry' => $this->inquiry,
'regAddress' => $this->regAddress,
];
$form = new InquiryForm(['inquiry' => $this->_inquiry, 'regAddress' => new Address()]);
$load = [
'regAddress' => $this->regAddress,
'inquiry' => $this->inquiry,
];
$form = new InquiryForm(['inquiry' => new Inquiry(), 'regAddress' => $this->_address]);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question