Testing: Overview. Testing is an indispensable process of software development.
Whether we are aware of it or not, we conduct testing all the time when we are developing a Web application. For example, when we write a class in PHP, we may use some echo or die statement to show that we implement a method correctly; when we implement a Web page containing a complex HTML form, we may try entering some test data to ensure the page interacts with us as expected. More advanced developers would write some code to automate this testing process so that each time when we need to test something, we just need to call up the code and let the computer to perform testing for us.
This is known as automated testing, which is the main topic of this chapter. YAML. PHPUnit and Selenium. Selenium. Functional Testing. Before reading this section, it is recommended that you read the Selenium documentation and the PHPUnit documentation first.
We summarize in the following the basic principles of writing a functional test in Yii: Like unit test, a functional test is written in terms of a class XyzTest which extends from CWebTestCase, where Xyz stands for the class being tested. CWebTestCase. Look up a class, method, property or event CWebTestCase is the base class for Web-based functional test case classes.
It extends PHPUnit_Extensions_SeleniumTestCase and provides the database fixture management feature like CDbTestCase. Public Properties Hide inherited properties Protected Properties Public Methods Hide inherited methods Protected Methods Property Details protected array $fixtures; a list of fixtures that should be loaded before each test method executes. Method Details Source Code:framework/test/CWebTestCase.php#59 (show) PHPUnit. Fixtures. Automated tests need to be executed many times.
To ensure the testing process is repeatable, we would like to run the tests in some known state called fixture. For example, to test the post creation feature in a blog application, each time when we run the tests, the tables storing relevant data about posts (e.g. the Post table, the Comment table) should be restored to some fixed state. The PHPUnit documentation has described well about generic fixture setup. In this section, we mainly describe how to set up database fixtures, as we just described in the example. Setting up database fixtures is perhaps one of the most time-consuming parts in testing database-backed Web applications. Before all tests run, it resets all tables relevant to the tests to some known state.Before a single test method runs, it resets the specified tables to some known state.During the execution of a test method, it provides access to the rows of the data that contribute to the fixture.
<? CDbFixtureManager. Look up a class, method, property or event.
Unit Testing. Because the Yii testing framework is built on top of PHPUnit, it is recommended that you go through the PHPUnit documentation first to get the basic understanding on how to write a unit test.
We summarize in the following the basic principles of writing a unit test in Yii: A unit test is written in terms of a class XyzTest which extends from CTestCase or CDbTestCase, where Xyz stands for the class being tested. CTestCase. CDbTestCase. Look up a class, method, property or event CDbTestCase is the base class for test cases about DB-related features.
CDbTestCase provides database fixture management with the help of CDbFixtureManager. By declaring fixtures property, one can ensure the specified tables have the expected fixture state when executing each test method. In addition, CDbTestCase provides two ways to access the fixture data. For example, assume we declare fixtures to be: public $fixtures=array( 'posts' => 'Post', 'comments' => 'Comment', ); We can access the original fixture data rows using $this->posts$this->posts['first post']. Protected Properties Hide inherited properties Public Methods Hide inherited methods Protected Methods Property Details protected array $fixtures; a list of fixtures that should be loaded before each test method executes. Netbeans, PHPunit and Yii. How to create PHPunit tests cases in Netbeans 6.8 for an Yii web application Ref.: Environment: Product Version: NetBeans IDE Dev (Build 200909221401) Java: 1.6.0_10; Java HotSpot™ Client VM 11.0-b15 System: Windows XP version 5.1 running on x86; Cp1252; es_ES (nb) Apache/2.2.6 (Win32) PHP/5.2.9-2 Yii framework 1.0.9 PHPUnit 3.3.15.
NetBeans IDE and Yii projects. This page is created to supply short directions and general tips for managing a Yii application in NetBeans IDE. 1.
Code completion ¶ To get context sensitive code completion, follow these steps: Include Yii folder (assuming it is properly placed outside project directory) Open "File > Project properties > PHP Include Path" and add the Yii framework root pathIgnore yiilite.php to avoid doubled/missing documentation Open "Tools > Options > Miscellaneous > Files"Add to the front of "Files Ignored by the IDE" the file "^(yiilite\.php|CVS|SCCS|....
"Restart NetBeansCode completion in view files Add the following PHPDoc statement at the head of the file to use code completion in view files. @var @var $this->getSomeProValue(); $model->author; Usage: Typing suggestions: Ctrl-SpaceShow Function parameters: Ctrl-PComment your own code with PHPDoc style.