There are actionBooks that get POST data about the book.

You need to write a test that will check whether the action received the data, whether the book is recorded in the database and return the answer if not.

I have already deployed a Codeception through Сomposer. Interested in the code itself, maybe someone has specific examples of test code, very little information, on the site of the site it is not clear how that works.

1 answer 1

Prepare a POST array and check. An example of saving a category.

public function testSaveCategory() { $category = new Category(); //simulate form input $postTrue = [ 'Category' => [ 'title' => "sdgerg", 'parent_id' => 8, ] ]; //simulate form input $postFalse = [ 'Category' => [ 'title' => 6848, 'parent_id' => 40, ] ]; $this->assertTrue($category->load($postTrue)); $this->assertTrue($category->save()); $this->assertTrue($category->load($postFalse)); $this->assertFalse($category->save()); } 

Arrays can be rendered in separate properties. You can extend checks using assert methods .

I also installed codeaverage (this is not necessary) to check, as a percentage, the code coverage of the tests. Run like this:

 codecept run unit --coverage --html 

But this is only unit testing. I also advise you to read this article.