25. PHPUnit - Running a Test Usage: phpunit [switches] UnitTest [UnitTest.php] --log-graphviz <file> Log test execution in GraphViz markup. --log-json <file> Log test execution in JSON format. --log-tap <file> Log test execution in TAP format to file. --log-xml <file> Log test execution in XML format to file. --coverage-html <dir> Generate code coverage report in HTML format. --coverage-xml <file> Write code coverage information in XML format. --test-db-dsn <dsn> DSN for the test database. --test-db-log-rev <r> Revision information for database logging. --test-db-prefix ... Prefix that should be stripped from filenames. --test-db-log-info ... Additional information for database logging. --filter <pattern> Filter which tests to run. --group ... Only runs tests from the specified group(s). --exclude-group ... Exclude tests from the specified group(s). --loader <loader> TestSuiteLoader implementation to use. --repeat <times> Runs the test(s) repeatedly. --tap Report test execution progress in TAP format. --testdox Report test execution progress in TestDox format.
26. PHPUnit - Running a Test Usage: phpunit [switches] UnitTest [UnitTest.php] --no-syntax-check Disable syntax check of test source files. --stop-on-failure Stop execution upon first error or failure. --verbose Output more verbose information. --wait Waits for a keystroke after each test. --skeleton Generate skeleton UnitTest class for Unit in Unit.php. --help Prints this usage information. --version Prints the version and exits. --configuration <file> Read configuration from XML file. -d key[=value] Sets a php.ini value.
27.
28. PHPUnit - Test Suites <?php if (! defined ( 'PHPUnit_MAIN_METHOD' )) define ( 'PHPUnit_MAIN_METHOD' , 'AllTests::main' ); require_once 'PHPUnit/Framework.php' ; require_once 'PHPUnit/TextUI/TestRunner.php' ; require_once 'MyTest.php' ; require_once 'MyOtherTest.php' ; class AllTests { public static function main () { PHPUnit_TextUI_TestRunner :: run ( self :: suite ()); } public static function suite () { $suite = new PHPUnit_Framework_TestSuite ( 'My Test Suite' ); $suite -> addTestSuite ( 'MyTest' ); $suite -> addTestSuite ( 'MyOtherTest' ); return $suite ; } } if ( PHPUnit_MAIN_METHOD == 'AllTests::main' ) AllTests :: main (); ?>
29.
30. PHPUnit - XML Configuration Running a list of tests <phpunit> <testsuite name="My Test Suite"> <directory suffix="Test.php"> mytests/directory </directory> <file> mytests/dirtory/fileTest.php </file> </testsuite> </phpunit>
31.
32. PHPUnit - XML Configuration <?php require_once( 'PHPUnit/Framework/TestCase.php' ); class SubStrTest extends PHPUnit_Framework_TestCase { /** * @group builtins */ public function testSubstr () { $this -> assertEquals ( 'o wo' , substr ( 'Hello world!' , 4 , 4 )); } } ?> >phpunit --configuration tests.xml --group builtins
33.
34.
35.
36.
37.
38.
39. PHPUnit - Skeleton Generator > phpunit --verbose CalculatorTest PHPUnit 3.2.19 by Sebastian Bergmann. CalculatorTest I Time: 0 seconds There was 1 incomplete test: 1) testAdd(CalculatorTest) This test has not been implemented yet. /home/mike/phpunit/CalculatorTest.php:65 OK, but incomplete or skipped tests! Tests: 1, Incomplete: 1.
40.
41.
42. PHPUnit - Skeleton Generator > phpunit --verbose CalculatorTest PHPUnit 3.2.19 by Sebastian Bergmann. CalculatorTest ..... Time: 0 seconds OK (5 tests)
43. PHPUnit - Skeleton Generator @assert (...) == X > assertEquals(X, method(...)) @assert (...) != X > assertNotEquals(X, method(...)) @assert (...) === X > assertSame(X, method(...)) @assert (...) !== X > assertNotSame(X, method(...)) @assert (...) > X > assertGreaterThan(X, method(...)) @assert (...) >= X > assertGreaterThanOrEqual(X, method(...)) @assert (...) < X > assertLessThan(X, method(...)) @assert (...) <= X > assertLessThanOrEqual(X, method(...)) @assert (...) throws X > @expectedException X
45. PHPUnit - Incomplete Tests Slide TODO: finish slide don't worry...just a little irony
46. PHPUnit - Incomplete Tests <?php require_once 'PHPUnit/Framework.php' ; class SampleTest extends PHPUnit_Framework_TestCase { public function testSomething () { // Optional: Test anything here, if you want. $this -> assertTrue ( TRUE , 'This should already work.' ); // Stop here and mark this test as incomplete. $this -> markTestIncomplete ( 'This test has not been implemented yet.' ); } } ?>
47. PHPUnit - SkippedTests <?php require_once 'PHPUnit/Framework.php' ; class DatabaseTest extends PHPUnit_Framework_TestCase { protected function setUp () { if (! extension_loaded ( 'mysqli' )) { $this -> markTestSkipped ( 'The MySQLi extension is not available.' ); } } } ?>
48. Advanced Features Mock Objects Database Testing Selenium RC PHPUnderControl Come see me again! Same room, same day, 3:30 PM