When a PHP class is written, step by step it is debugged or die or echo statements method is used to check how it is working. When a web application is developed, the test data is entered in forms to ensure working of the page as desired and expected. The test process can be automated.
Automatic test approach is used for long term projects like:
Step 1 − Install the Codeception framework. Run the following code.
Step 2 − Run the following.
The output is “Changed current directory to <directory>”. You should add the '<directory>/vendor/bin' to your PATH variable. In this case, run the following code −
Step 3 – A new database 'yii2_basic_tests' is created.
Step 4 − Inside the tests directory run
The database configuration can be found at tests/codeception/config/config.php.
Step 5 – Test suites are built through
Yii Fixtures facilitate in running the tests in an expected way by setting the environment in an unknown state. A near fixture framework is provided by Yii. A key concept of the Yii fixture framework is the fixture object. It represents a particular aspect of a test environment. The fixture object is an instance of the yii estFixture class.
A fixture is defined by creating a new class and extending it from yii estFixture or yii estActiveFixture. The former is better for general purpose fixtures while the latter is specifically designed to work with database and ActiveRecord.
Individual functions like model functions or a component class are tested by Unit tests.
Step 1 − A new fixture is created in the file ExampleFixture.php under the tests/codeception/fixtures directory.
Step 2 − A new test file ExampleTest.php is created in the tests/codeception/unit/models folder.
Three tests are defined in the above code −
A new user is created and the name is updated and try to delete. The MyUser model is managed in terms of the yii2_basic_tests database, which is a complete copy of our real DB.
Step 3 − Tests, are started by moving to the tests folder and run.
Once it passes all the tests, the following output appears:
Functional tests help in −
Run the following in the tests folder -
A file AboutPageCept.php is created under tests/codeception/functional folder. In the functional test the existence of about page is checked.
Step 1 −The AboutPageCept.php file is modified by:
In the above given code, we checked whether we are on the about page. Obviously, the word 'about' should appear on the page.
Step 2 − Run the test through:
The output appears as:
Yii Related Interview Questions
|PHP Interview Questions||Zend Interview Questions|
|PHP and Jquery Interview Questions||PHP+MySQL Interview Questions|
|Sybase Interview Questions||Dbase Interview Questions|
|Magento Interview Questions||PHP5 Interview Questions|
|WordPress Interview Questions||CakePHP Interview Questions|
|CodeIgniter Interview Questions||Firebase Interview Questions|
|SQLite Interview Questions||PHP7 Interview Questions|
|Object Oriented Programming in PHP Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.