PHPUnit doc suggested alterations
| From: | Andrew Braund | Date: | Tue, 25 Mar 2003 04:53:47 +0000 |
| Subject: | PHPUnit doc suggested alterations | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-517@lists.php.net to get a copy of this message | ||
There are some functions in Assert.php that are not shown in the documentation
such as assertRegExp(). Also the version at cvs.php.net is not the same as
what is displayed in the manual at
http://pear.php.net/manual/en/packages.phpunit.tutorial.php
It shows;
Work routine
Normal, ...
while intro.xml in cvs shows;
Work routine
Normally, ...
My understanding is that the html is generated from the xml (and the source?).
Is this a manual process that has not been done for a while?
I manually install PEAR, (I have recently (4.3.2RC1) tried go-pear.bat but it
is broken for me).
PHPUnit.php is in
c:/php/pear/PHPUnit.php
not
c:/php/pear/PHPUnit/PHPUnit.php
so the example scripts in the tutorial do not work as is.
Some diffs;
Index: intro.xml
===================================================================
RCS file: e:/cvsweb/peardoc/en/packages/php/PHPUnit/intro.xml,v
retrieving revision 1.1.1.1
diff -u -3 -r1.1.1.1 intro.xml
--- intro.xml 25 Mar 2003 01:04:22 -0000 1.1.1.1
+++ intro.xml 25 Mar 2003 03:08:39 -0000
@@ -19,7 +19,7 @@
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
+ You do not have 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.
</para>
@@ -27,7 +27,7 @@
<refsect1 id="packages.php.phpunit.intro.workroutine">
<title>Work routine</title>
<para>
- Normally, you would write a class, do some unsystematic tests
+ Normally, you would write a class, then do some unsystematic tests
using <function>echo</function> or <function>var_dump</function>.
After this, you use the class in your application and hope everything
is ok.
@@ -104,7 +104,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 ----
@@ -145,7 +145,7 @@
function testToString() {
$result = $this->abc->toString('contains %s');
$expected = 'contains abc';
- $this->assertTrue($result == $expected);
+ $this->assertEquals($expected, $result);
}
// test the copy function
@@ -160,7 +160,7 @@
$this->abc->add($abc2);
$result = $this->abc->toString("%s");
$expected = "abc123";
- $this->assertTrue($result == $expected);
+ $this->assertEquals($expected, $result);
}
}
?>
@@ -180,7 +180,7 @@
<?php
require_once 'testcase.php';
-require_once 'PHPUnit/PHPUnit.php';
+require_once 'PHPUnit.php';
$suite = new PHPUnit_TestSuite("StringTest");
$result = PHPUnit::run($suite);
@@ -195,9 +195,9 @@
this output:
<programlisting>
<![CDATA[
-TestCase stringtest->testtostring() failed: expected true, actual false
+TestCase stringtest->testtostring() failed: expected contains abc, actual
TestCase stringtest->testcopy() failed: expected , actual Object
-TestCase stringtest->testadd() failed: expected true, actual false
+TestCase stringtest->testadd() failed: expected abc123, actual
]]>
</programlisting>
Every function fails the test, because your string functions
@@ -256,7 +256,7 @@
~> <command>php -f stringtest.php</command>
TestCase stringtest->testtostring() passed
TestCase stringtest->testcopy() passed
-TestCase stringtest->testadd() failed: expected true, actual false
+TestCase stringtest->testadd() failed: expected abc123, actual abc123s
</programlisting>
D'oh! the last test failed! We did a typing mistake. Change
line 16 in <filename>string.php</filename> to
@@ -280,7 +280,7 @@
<para>
Hm, such a big expenditure 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
Regards
Andrew Braund