10.04.2018 Views

Doctrine_manual-1-2-en

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 27: Unit Testing 358<br />

}<br />

}<br />

// This produces a failing test<br />

public function testTest()<br />

{<br />

$this->assertTrue($this->myModel->exists());<br />

$this->assertEqual(0, 1);<br />

$this->assertId<strong>en</strong>tical(0, '0');<br />

$this->assertNotEqual(1, 2);<br />

$this->assertTrue((5 < 1));<br />

$this->assertFalse((1 > 2));<br />

}<br />

class Model1 ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

}<br />

class Model2 ext<strong>en</strong>ds <strong>Doctrine</strong>_Record<br />

{<br />

}<br />

The model definitions can be included directly in the test case file or they can be put in<br />

/path/to/co/doctrine/tests/models and they will be autoloaded for you.<br />

Once you are finished writing your test be sure to add it to run.php like the following.<br />

Listing<br />

27-8<br />

$test->addTestCase(new <strong>Doctrine</strong>_Sample_TestCase());<br />

Now wh<strong>en</strong> you execute run.php you will see the new failure reported to you.<br />

Ticket Tests<br />

In <strong>Doctrine</strong> it is common practice to commit a failing test case for each individual ticket that<br />

is reported in trac. These test cases are automatically added to run.php by reading all test<br />

case files found in the /path/to/co/doctrine/tests/Ticket/ folder.<br />

You can create a new ticket test case easily from the CLI:<br />

Listing<br />

27-9<br />

$ php run.php --ticket 9999<br />

Listing<br />

27-10<br />

If the ticket number 9999 doesn't already exist th<strong>en</strong> the blank test case class will be<br />

g<strong>en</strong>erated for you at /path/to/co/doctrine/tests/Ticket/9999TestCase.php.<br />

class <strong>Doctrine</strong>_Ticket_9999_TestCase ext<strong>en</strong>ds <strong>Doctrine</strong>_UnitTestCase<br />

{<br />

}<br />

Methods for testing<br />

Assert Equal<br />

Listing<br />

27-11<br />

// ...<br />

public function test1Equals1()<br />

{<br />

----------------- Brought to you by

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

Saved successfully!

Ooh no, something went wrong!