PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1

CHAPTER 18 ■ TESTING WITH PHPUNIT


Notice that each command is divided into three parts: command, target, and value. These
subdivisions are also known as actions, accessors, and assertions. Essentially, a command then instructs
the test engine to perform something (an action), somewhere (accessor), and then to confirm a result
(assertion).
Now I can return to my WOO web interface, add a venue, confirm some text, add a space, and
confirm again. Ultimately, I will end up with a runable test case. I can run it in the IDE itself by hitting
one of the green “play” buttons at the stop of the IDE control panel. Failed test commands will be
flagged red, and passes flagged green.
You can save your test case from the File menu, and rerun it at a later date. Or you can export your
test as a PHPUnit class. To do this, choose Format from the Options menu and select PHPUnit. You can
see the menu in Figure 18–4.


Figure 18–4. Changing the format


Note the log pane at the bottom of the panel. You can see a report there from a successful run of the
test case. Now that I’ve set the correct format, it’s a matter of saving the file. As you might expect, you
can choose Save As from the File menu. Here’s the contents of the saved file:


class Example extends PHPUnit_Extensions_SeleniumTestCase
{
function setUp()
{
$this->setBrowser("*firefox");
$this->setBrowserUrl("http://localhost/webwoo/");
}


function testMyTestCase()
{
$this->open("/webwoo/?cmd=AddVenue");
try {

Free download pdf