Content of the «Testing» section The Definitive Guide to Yii 2.0:
Articles section «Testing» The Definitive Guide to Yii 2.0:
Fixtures are an important part of testing. Their main purpose is to set up the environment in a fixed/known state so that your tests are repeatable and run in an expected way. Yii provides a fixture framework that allows you to define your fixtures precisely and use them easily both when running your tests with Codeception and independently.
Acceptance test verifies scenarios from a user's perspective. The application tested is accessed via either PhpBrowser or a real browser. In both cases the browsers are communicating via HTTP so application should be served via web server.
Functional test verifies scenarios from a user's perspective. It is similar to acceptance test but instead of communicating via HTTP it is filling up environment such as POST and GET parameters and then executes application instance right from the code.
A unit test verifies that a single unit of code is working as expected. That is, given different input parameters, the test verifies the class method returns expected results. Unit tests are usually developed by people who write the classes being tested.
Testing environment setup
Yii 2 has officially maintained integration with
Codeception testing framework that allows you to create the following test types:
- Unit - verifies that a single unit of code is working as expected;
- Functional - verifies scenarios from a user's perspective via browser emulation;
- Acceptance - verifies scenarios from a user's perspective in a browser.
Testing is an important part of software development. Whether we are aware of it or not, we conduct testing continuously. For example, when we write a class in PHP, we may debug it step by step or simply use
die statements to verify the implementation works according to our initial plan. In the case of a web application, we're entering some test data in forms to ensure the page interacts with us as expected.