Doctest in PHP

Dana prefers Haskell
Doctest is a Python module which allows including tests in the comments (those called doctring). There’s a PHP Pear module Doctest version.
DocTest is an easy way to write tests because using tools such as PHPUnit or Simpletest require a Test Driven Development methodology. Besides, doctests aren’t really an alternative to unit tests but something complementary.
Installing via PEAR:
The doctest is included between <code> tags. The expected output is written after “// expects:”.
Running the tests :
The test output :
[PASS] function mostrarNumeros
Total time : 0.0253 sec.
Passed tests : 1
Skipped tests : 0
Failed tests : 0
The doctest is usually included next to the phpdoc comment, omitted for clearness.
Doctest by default only considers the test as successful if the output looks exactly the same as the written expected output.
However we can use flags to change this behaviour:
- NORMALIZE_WHITESPACE: white spaces are ignored.
- CASE_INSENSITIVE:
- SKIP: the test is ignored
- ELLIPSIS: you can use a wildcard as [...]. It’s useful for partial unknown outputs.
An example that uses the ELLIPSIS tag and shows that It’s possible having several tests in the same header:
-
-
<?php
-
/**
-
* <code>
-
* // Usamos ELLIPSIS porque hay una parte de la salida que no podemos predecir
-
*
-
* // flags: ELLIPSIS
-
* echo testString();
-
* // expects:
-
* // Lo siguiente no se puede predecir [...].
-
*
-
* </code>
-
*
-
* <code>
-
* // Este es el mismo test pero lo hacemos para ver que podemos dividir la salida con \
-
*
-
* // flags: ELLIPSIS
-
* echo testString();
-
* // expects:
-
* // Lo siguiente \
-
* // no se puede \
-
* // predecir [...].
-
*
-
* </code>
-
*
-
*/
-
function testString()
-
{
-
}
If the output is too big We can use “expects-file:” instead of “expects :”.
We put the raw expected output in mostrarNumeros.txt.
You can also include the whole test in an external file:
-
-
* <code>
-
* // test-file: tests/test1.doctest
-
* </code>
Besides, you might need including code to be interpreted before, useful for things like environmental variables or simulating a HTTP request.
-
-
/**
-
* This is a file level test.
-
*
-
* <code>
-
* // setup:
-
* // $_ENV['OSTYPE'] = ‘linux’;
-
* echo OS_TYPE;
-
* // expects:
-
* // linux
-
* </code>
-
*/
Links:
http://code.google.com/p/testing-doctest/
http://pear.php.net/package/Testing_DocTest
http://en.wikipedia.org/wiki/Doctest
http://svn.php.net/repository/pear/packages/Testing_DocTest/trunk/tests/test1.php
(Español) Las referencias en PHP: qué son y el porqué de no usarlas
Sorry this post is only in Spanish :
http://ivanmosquera.net/index.php/2010/02/13/las-referencia…que-no-usarlas/?lang=es
Flash/Flex development in Linux : Minibuilder
Adobe no longer develops Flash/Flex Builder for Linux. I’ve found a promising opensource alternative : Minibuilder. It’s an IDE built with Adobe Air.

flash platform
Let’s see how to install and use this tool:
(more…)
(Español) Probando Haxe
Sorry, this entry is only available in Español.
(Español) Ikuspro en beta
Sorry, this entry is only available in Español.
(Español) Editores UML gratuitos
Sorry, this entry is only available in Español.