Answer the question
In order to leave comments, you need to log in
How to write tests for a Yii2 application?
Good day to all. There are difficulties with understanding what needs to be tested using different types of tests. Difficulties are generated by various classifications of tests found on the Internet. Somewhere you can find the phrases "functional / acceptance", somewhere "functional / integration".
If you look at the tests that come with yii2-advanced and yii2-basic, the question arises why, in the presence of acceptance, functional are needed. In essence, they simply check for the presence of certain strings in the server's responses. In acceptance tests, you can do the same, and even with the ability to specify CSS selectors for the lines that you need to check for.
Additional questions are generated by the article . In Yii, even the banal
$model = \Mockery::mock(News::className())->shouldReceive('save')->once()->andReturn(true)->getMock();
$model->title = 'Первый пост';
news
. "Kill" all calls to the database, as I understand it, will not succeed. Especially so that the tests retain a readable form. What remains to be tested with unit tests in this case? public function setSuccessStatus()
{
$this->status = self::STATUS_SUCCESS;
return $this->save();
}
public function testSetSuccessStatus()
{
$post = $this->getMockBuilder('\app\model\Post')->setMethods(['save'])->getMock();
$post->method('save')->willReturn(true);
$post->setSuccessStatus();
$this->assertEquals($post->status, Post::STATUS_SUCCESS);
}
$post->status
test will get into the database to find out if there is a field in it status
. Am I misunderstanding something?
Answer the question
In order to leave comments, you need to log in
In Yii, even the banal ... spawns a database query to get the structure of the news table.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question