cvs: peardoc /en/package/php/phpunit intro.xml

From: Date: Sun, 03 Oct 2004 11:38:47 +0000
Subject: cvs: peardoc /en/package/php/phpunit intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-4929@lists.php.net to get a copy of this message
mj Sun Oct 3 07:38:47 2004 EDT Modified files: /peardoc/en/package/php/phpunit intro.xml Log: * Improved version of the introduction to PHPUnit. Patch by: Aaron Wormus http://cvs.php.net/diff.php/peardoc/en/package/php/phpunit/intro.xml?r1=1.4&r2=1.5&ty=u Index: peardoc/en/package/php/phpunit/intro.xml diff -u peardoc/en/package/php/phpunit/intro.xml:1.4 peardoc/en/package/php/phpunit/intro.xml:1.5 --- peardoc/en/package/php/phpunit/intro.xml:1.4 Tue Oct 14 18:54:40 2003 +++ peardoc/en/package/php/phpunit/intro.xml Sun Oct 3 07:38:47 2004 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.4 $ --> +<!-- $Revision: 1.5 $ --> <refentry id="packages.php.phpunit.intro"> <refnamediv> <refname>Tutorial</refname> @@ -9,20 +9,20 @@ <refsect1> <title>A short introduction to the test framework</title> <para> - <classname>PHPUnit</classname> gives you a simple - framework for creating a test application to + <classname>PHPUnit</classname> provides a simple + framework for creating a test suite to automate testing of functions and classes. PHPUnit is inspired by - <ulink url="&url.junit;">JUnit</ulink>. - Kent Beck and Erich Gamma created JUnit as a tool - for <ulink url="&url.extreme.prog;"> - eXtreme Programming</ulink>. One of the parts of XP + <ulink url="&url.junit;">JUnit</ulink> which was created by + Kent Beck and Erich Gamma as a tool for <ulink url="&url.extreme.prog;"> + eXtreme Programming</ulink>. One of the rules of XP is to test small software components as often and early - as possible and not to fix bugs and errors in the API - while setting up and testing the whole application. - You have not to switch to XP to benefit from PHPUnit. It - is a good tool for testing classes or a set of functions - and helps you to avoid endless debug sessions. + as possible, this way you will not have to fix bugs and errors in the API + while setting up and testing larger applications which depend on the class. + While unit testing is one of the fundimental rules in XP, you don't have + to switch to XP to benefit from PHPUnit. PHPUnit stands alone as a good + tool for testing classes or a set of functions and will ease your + development cycle and help you to avoid endless debug sessions. </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.workroutine"> @@ -51,7 +51,7 @@ <para>5. fix failures or errors and go to #4 again</para> </listitem> </itemizedlist> - This seems to require a lot of time, but this impression is + It may seem that this will require a lot of time, but this impression is wrong. Creating the test suite using PHPUnit needs only a few minutes and running the test suite only seconds. </para> @@ -105,7 +105,7 @@ with the result of the function to test. The result of this compare must delegate to a function of the <function>assert*</function>-family, which decides - if a function pass or fail the test. + if a function passes or fails the test. <programlisting role="php"> <![CDATA[ ---- testcase.php ---- @@ -172,8 +172,8 @@ <refsect1 id="packages.php.phpunit.intro.firstrun"> <title>The first test run</title> <para> - Now, we can run a first test. Execute this PHP program. - Make sure that the paths are correct. + Now, we can run a first test. Make sure that all the paths are correct and + then execute this PHP program. <programlisting role="php"> <![CDATA[ ---- stringtest.php ---- @@ -192,8 +192,8 @@ </programlisting> </para> <para> - If you call this script through commandline, you will get - this output: + If you call this script from the commandline, you will get + the following output: <programlisting> <![CDATA[ TestCase stringtest->testtostring() failed: expected true, actual false @@ -252,14 +252,14 @@ </programlisting> </para> <para> - Implementing is done and run the test again: + The implementation is complete and we can run the test again: <programlisting> ~> <command>php -f stringtest.php</command> TestCase stringtest->testtostring() passed TestCase stringtest->testcopy() passed TestCase stringtest->testadd() failed: expected true, actual false </programlisting> - D'oh! the last test failed! We did a typing mistake. Change + D'oh! the last test failed! We made a typing mistake. Change line 16 in <filename>string.php</filename> to <programlisting role="php"> <![CDATA[ @@ -273,21 +273,27 @@ TestCase stringtest->testcopy() passed TestCase stringtest->testadd() passed </programlisting> - Everything is ok now! + Everything is now OK! </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.conclusion"> <title>Conclusion</title> <para> - Hm, such a big expenditure for testing three simple + Does it seem like a lot of work for testing three simple functions? Don't forget, this is a small example. - Think about bigger, complexer API's like database + Think about bigger, more complex API's like database abstraction or basket classes in a shop application. PHPUnit is an excellent tool to detect errors in the - implementation. Maybe you have a big class used - in a few applications and you want to reimplement - the class. With a test suite, you can easily check - and fix the new implementation in a short session. + implementation of your class. + </para> + <para> + Often you will want to reimplement or refactor a large class which is + used in several different applications. Without a test suite the + likeliness of you breaking something in one of the applications that + depends on your class is very high. Thanks to unit tests, you can create + a test suite for your class, and then reimplement your class with the + security of knowing that as long as the new class passes the tests, + applications that depend on the class will work. </para> </refsect1> </refentry>

« previous php.pear.doc (#4929) next »