Test Driven (Plugin) Development

On my local 2.1.1-B1 github master branch development installation I’m just trying to add unit testing support (by phpUnit integration) to my plugin still under development.

So I’ve managed to getting started my plugin running the console command:

php console generate:plugin --name=myPluginName

Then I’ve added unit testing support with the following command:

php console generate:test

Then I’ve run the default test on the plugin, the command to run tests is:

php console tests:run myPluginName

The problem is console stills frozen until I CTRL+C… Any advice is welcome.

Good that you are trying Test Driven Development for your plugin!

First you need to setup PHPUnit as explained in matomo/README.md at master · matomo-org/matomo · GitHub

Maybe this was not clear. Let us know if that helps or how we can make documentation better and more clear to plugin developers

Hello Matt, thank you for reply.

I’ve read that readme file, then I’ve ended up using this method for testing:

[li] Installed Composer and phpUnit by phar package
[/li][li] Configured phpunit.xml file as needed
[/li][li] Run tests using www-data user:

su www-data -c "php console tests:run"


Console hangs for minutes until with no output until CTRL+C… Is there some debug option? My environment is Ubuntu Server LTS 12.04 on a Virtualbox VM. You see… phpUnit by Pear is no more supported, go with phar instead.

[EDIT] after going to lunch for half an hour I left tests running and I got back a curl timeout error. Can I configure curl into config.inc.php also for tests, as did for database_tests?

Try to run the tests only for your plugin, for this example this will run CustomAlerts tests:

./console tests:run CustomAlerts

The core tests take a very long time to run and we don’t run them all on our boxes, we wait for results from travis Travis CI - Test and Deploy Your Code with Confidence

Thank you Matt for helping but I can’t sort it out. :frowning:

In the beginning, the first post, I’ve just tried testing the default plugin’s fresh console generated tests (assert 2 is 1+1) but as you know console hangs just after outputting Executing command: “cd /var/www/piwik/tests/PHPUnit && phpunit --group=myPluginName” (for each group I mention)

I’ve tried to remove bootstrap.php from phpunit.xml configuration and it gave me fatal error (of course).
Then I’ve undo and tried to remove @ characters before method calls into bootstrap.php but it’s still hanging.

I’m working behind Proxy because of company limits, this isn’t a problem running piwik by http browser, because I’ve configured accordlying config.ini.php proxy section. I can’t say if I need some kind of proxy config for php-cli environment. (my php.ini is development version distributed with ubuntu)

Well, I’ve sorted out because wasn’t working. The problem was that Piwik was trying to test using proxy configuration enabled to reach the marketplace into UI admin interface. Would be great having different environments support defining variables into config.inc.php.

For example something like database section that’s already working:

host = ""
port = 3128
username = "proxyUser"
password = "proxyPass"

host = ""
port = ""
username = ""
password = ""