Your code is sh*t!
Don't believe?
Ask your yesterday-self
$ # Usage phar$ wget https://phar.phpunit.de/phpunit.phar$ chmod +x phpunit.phar$ mv phpunit.phar /usr/local/bin/phpunit$ # Using composer to require phpunit for your own project$ echo '{ "require-dev": { "phpunit/phpunit": "~4.1" } }' > composer.json$ # Using composer to install global$ composer global require "phpunit/phpunit=4.1.*"
class My_Class_Test extends PHPUnit_Framework_TestCase {
public function testMethodX() { $this->assertTrue(true); }
public function testMethodY() { $this->assertFalse(true, ''); }
}
$ phpunit My_Class_Test.php
PHPUnit 4.1.3 by Sebastian Bergmann.
.F
Time: 43 ms, Memory: 3.00Mb
There was 1 failure:
1) My_Class_Test::testMethodY
Failed assert
Failed asserting that true is false.
FAILURES!
Tests: 2, Assertions: 2, Failures: 1.# From http://phpunit.de/manual/4.1/en/organizing-tests.html
src tests
`-- autoload.php `-- bootstrap.php
`-- Currency.php `-- CurrencyTest.php
`-- IntlFormatter.php `-- IntlFormatterTest.php
`-- Money.php `-- MoneyTest.php
class My_Class_Test extends PHPUnit_Framework_TestCase {
public function setUpBeforeClass() {}
public function setUp() {}
public function testMethodX() { $this->assertTrue(true); }
public function testMethodY() { $this->assertFalse(true, ''); }
public function tearDown() {}
public function tearDownAfterClass() {}
}

class My_Class_Test extends PHPUnit_Framework_TestCase {
/**
* @expectedException RuntimeException
* @expectedExceptionMessage Unimplemented functionality
*/
public function testException() {
// try things…
}
}
class My_Class_Test extends PHPUnit_Framework_TestCase {public function testInvisibleMethod() {$obj = new My_Class();$ref = new ReflectionClass($obj); $ref->getMethod('myPrivateMethod')->setAccessible(true);$results = $obj-> myPrivateMethod();$this->assertNotEmpty($results); } }
class My_Class_Test extends PHPUnit_Framework_TestCase
{
public function testDouble()
{
$generator = $this->getMock('PDFGenerator');
$generator
->expects($this->once())
->method('generate')
->with('<html>…')
->willReturn(new PDFFile());
$my_web_page = new WebPage();
$my_web_page->print($driver = 'pdf');
}
}$ phpunit --coverage-text
$ phpunit --coverage-html /path/to/report
$ # screenshot => google images