Test-driven development (TDD)

Test-driven development (TDD)

Unit testing PHP

Test-Driven PHP | Nettuts+

How to test an API that must be authenticated via session? Maybe with Vows.js

Database

Unit testing setup in PHP 5.4

Install PHPUnit

Needed extensions:

apt-get -y install php5-curl php5-xdebug php5-imap

Discover PEAR channels:

pear channel-discover pear.phpunit.de
<!-- pear channel-discover pear.symfony-project.com (thats version 1) -->
pear channel-discover pear.symfony.com
pear channel-discover components.ez.no
pear install phpunit/PHPUnit
pear install phpunit/DbUnit
<!-- This one does not work: pecl install phpunit/test_helpers  -->

Alternative:

pear upgrade pear
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit

Interesting PEAR command:

pear config-show, pear config-get php_dir

Test_helpers not compiling in PHP 5.4, so we need a patched version: Patch: https://raw.github.com/whatthejeff/php-test-helpers/c04ae7e2f591592480696d0a5ea0fec1340e8dbb/test_helpers.c

So, let’s use, until patch is promoted upstream:

git clone https://github.com/whatthejeff/php-test-helpers.git /tmp/test_helpers

cd /tmp/test_helpers phpize ./configure make && make install cd - rm -rf /tmp/test_helpers

echo “extension=test_helpers.so” > /etc/php5/conf.d/20-phpunit_test_helpers.ini

phpize is a binary that comes with PHP - it prepares the extension to be compiled, the rest is pretty straightforward pecl install

sebastianbergmann/php-test-helpers · GitHub whatthejeff/php-test-helpers · GitHub

pear channel-discover pear.symfony.com pear install pear.symfony.com/Yaml

pear install –alldeps pear.phpunit.de/PHPUnit

How do I correctly install PHPUnit with PEAR?

Runkit

This won’t work:

pecl install http://github.com/downloads/zenovich/runkit/runkit-1.0.3.tgz

And here is why:

The PHP5.4.x will be supported as of version 1.4 of runkit. If you need runkit in PHP5.4 right now, please use the runkit from master branch of http://github.com/zenovich/runkit (2012-08-26 by dzenovich@php.net)

Mentioned here: https://bugs.php.net/bug.php?id=61189

git clone http://github.com/zenovich/runkit.git /tmp/runkit

cd /tmp/runkit phpize ./configure make && make install cd - rm -rf /tmp/runkit

echo " ; Enable pecl-runkit extension module extension=runkit.so

[runkit] ; Sets possibility to override PHP internal functions by runkit_function_redefine() runkit.internal_override=1 " >/etc/php5/conf.d/20-runkit.ini

Needed configurations for Unit testing:

echo “; Increase as needed for unit testing upload_max_filesize = 32M post_max_size = 32M " >/etc/php5/conf.d/20-maxsize_limits.ini

Notice: looks like you can use also: https://github.com/php/pecl-php-runkit

Example to install - compile runkit: S:\www\playground\devbox-research\chef\cookbooks.io_github\yv-cookbook-eaccelerator\recipes\default.rb S:\www\playground\devbox-research\chef\easybib-cookbooks\php-mysqlnd_uh\recipes\compile.rb

date 01. Jan 0001 | modified 10. Jun 2024
filename: Test-driven development (TDD)