20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

estored to some fixed state. The PHPUnit <strong>do</strong>cumentation has described well about<br />

generic fixture setup. In this section, we mainly describe how to set up database fixtures,<br />

as we just described in the example.<br />

Setting up database fixtures is perhaps one of the most time-consuming parts in testing<br />

database-backed Web applications. <strong>Yii</strong> introduces the CDbFixtureManager application<br />

component to alleviate this problem. It basically <strong>do</strong>es the following things when running a<br />

set of tests:<br />

• Before all tests run, it resets all tables relevant to the tests to some known state.<br />

• Before a single test method runs, it resets the specified tables to some known state.<br />

• During the execution of a test method, it provides access to the rows of the data that<br />

contribute to the fixture.<br />

To use CDbFixtureManager, we configure it in the application configuration as follows,<br />

return array(<br />

'components'=>array(<br />

'fixture'=>array(<br />

'class'=>'system.test.CDbFixtureManager',<br />

),<br />

),<br />

);<br />

We then provide the fixture data under the directory protected/tests/fixtures. This directory<br />

may be customized to be a different one by configuring the CDbFixtureManager::basePath<br />

property in the application configuration. The fixture data is organized as a collection of<br />

PHP files called fixture files. Each fixture file returns an array representing the initial rows<br />

of data for a particular table. The file name is the same as the table name. The following is<br />

an example of the fixture data for the Post table stored in a file named Post.php:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!