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.

The testing supported provided by <strong>Yii</strong> requires PHPUnit 3.4+ and Selenium Remote<br />

Control 1.0+. Please refer to their <strong>do</strong>cumentation on how to install PHPUnit and Selenium<br />

Remote Control.<br />

When we use the yiic webapp console command to create a new <strong>Yii</strong> application, it will<br />

generate the following files and directories for us to write and perform new tests:<br />

testdrive/<br />

protected/<br />

tests/<br />

fixtures/<br />

functional/<br />

unit/<br />

report/<br />

bootstrap.php<br />

phpunit.xml<br />

WebTestCase.php<br />

containing protected application files<br />

containing tests for the application<br />

containing database fixtures<br />

containing functional tests<br />

containing unit tests<br />

containing coverage reports<br />

the script executed at the very beginning<br />

the PHPUnit configuration file<br />

the base class for Web-based functional tests<br />

As shown in the above, our test code will be mainly put into three directories: fixtures,<br />

functional andunit, and the directory report will be used to store the generated code<br />

coverage reports.<br />

To execute tests (whether unit tests or functional tests), we can execute the following<br />

commands in a console win<strong>do</strong>w:<br />

% cd testdrive/protected/tests<br />

% phpunit functional/PostTest.php // executes an individual test<br />

% phpunit --verbose functional // executes all tests under<br />

'functional'<br />

% phpunit --coverage-html ./report unit<br />

In the above, the last command will execute all tests under the unit directory and generate<br />

a code-coverage report under the report directory. Note that xdebug extension must be<br />

installed and enabled in order to generate code-coverage reports.<br />

Test Bootstrap Script<br />

Let's take a look what may be in the bootstrap.php file. This file is so special because it is<br />

like the entry script and is the starting point when we execute a set of tests.

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

Saved successfully!

Ooh no, something went wrong!