PHPUnit and Facebook’s php-webdriver

This seems straight forward at first, but there is either an autoloading issue in my project, or the author of the blog assumed everyone would know about PHP “namespaces” and how to “use” (aka “import” in Java) the external classes.

Namespace tutorial: http://daylerees.com/php-namespaces-explained/

Once namespace imports were working, there was another error:

Call to undefined function Facebook\WebDriver\Remote\curl_init()

This was fixed by installing curl into PHP: sudo apt-get install php5-curl. Check it installed properly: php -info | grep -i curl

/etc/php5/cli/conf.d/20-curl.ini,
curl
cURL support => enabled
cURL Information => 7.38.0

PhpUnit error with PhpStorm 9.0.2

I have enjoyed using Eclipse PDT for my PHP development, but everyone else on the team is switching to PhpStorm, so I have put off the transition as long as possible, but today was the official cut off. In addition, I decided to go all out on the switch and begin doing all of my development in an Ubuntu VM on my Windows 10 machine. PHP was designed for Linux, and the ease of installation in Linux vs. Windows is well worth the time of getting a VM up and running.

One issue I ran into with PhpStorm v9.0.2 and PhpUnit v5.0.3 is a call to an undefined function:


PHP Fatal error: Call to undefined method PHP_CodeCoverage_Filter::addFileToBlacklist() in ~/.phpstorm_helpers/phpunit.php on line 321

For now, the way I fixed this was to downgrade my version of PhpUnit from 5.* to 4.8.* in my compser.json:


{
"require-dev": {
"phpunit/phpunit": "4.8.*"
}
}

Hope this saves someone else the time and effort I lost into trying to “fix” this issue while waiting for PhpUnit 5.1 in December.

PHP Test Frameworks

I’ve got a PHP project that desperately needs some basic Unit Testing. I am a huge fan of building automated tests as I develop code, and (mostly) before I even write the implementations. “How do we test this?” is one of the 2 most important questions in software development. (The other being “How do we define ‘done'”)

JUnit has been amazing for my Java development, so having a PHP test framework that is similar, or based off of its ideas is a big plus if I can get it.

There are a lot of good options out there that look good, but I have not had a chance to review all of them yet. The main ones considered at this point are:

  1. SimpleTest
    • PROS: easy to get up and running, just download the tar.gz file, unzip, and go. It is also very JUnit like in the Java world (TestSuites, run functions that start with the word “test”, etc.).
    • CONS: latest version was released in 2012
  2. Testify.php
    • PROS: easy to get up and running
    • CONS: not updated since August of 2014, and does not seem to be as JUnit-like as I’d prefer, but maybe that is due to the lack of documentation, and my lack of time to research it
  3. PHPUnit – The PHP Testing Framework
    • PROS: most up-to-date and seems very enterprise ready (latest version was released about a week ago as of this writing)
    • CONS: install is not as easy as the others. It requires a PHAR file (not a real big issue), but it is not as easy as the others to get going in a Windows environment (again, not a huge problem, but it is more involved than the others)

In the end I decided to go with SimpleTest because its first few tutorials were very easy to get up and running, and it is very JUnit-like. The code base is also only running PHP 5.3.3, so it is on an older version of PHP, and the fact that SimpleTest (and Testify.php) were a little dated is not as big of an issue, and probably easier (as to not mix features of newer PHP versions) at this point in time.

At some point I should at least go through the Testify.php tutorials to see if it is a viable option.