- Published on
Pear, PHPUnit, MAMP and SilverStripe Unit Testing
- Authors
- Name
- Frank
Installing PHPUnit using Pear on Mac OSX was such a process I have to write it down. If you want to get started with unit testing in SilverStripe you need PHPUnit installed.
Installing Pear and PHPUnit
If you have MAMP installed on Mac OSX 10.6, you probably have Pear installed already and just need to alter your $PATH to make it available. I followed the instructions to install Pear on this blog post which was the best guide I could find and the only one to work for me.
After that is working, I had to add some channels to Pear in order to install PHPUnit.
After all this, php.ini should have Pear in the include path, something like:
.:/Applications/MAMP/bin/php5.3/share/pear:/Applications/MAMP/bin/php5.3/lib/php
Don't forget to restart Apache at this point to reload the php.ini changes.
The actual files for PHPUnit will likely live at:
/Applications/MAMP/bin/php5.3/share/pear/PHPUnit
This is where you will find Autoload.php and Framework.php.
Running SilverStripe Unit Tests
You should now be able to browse to /dev/tests/ in order to run some SilverStripe unit tests. You should see some output regarding how many tests were run, which passed and which failed. This was not appearing for me and the reason was because my MySQL user did not have the necessary permissions to create a temporary MySQL table.
So, if you are debugging issues here, and notice that there are no errors being reported in log files for Apache etc. make sure you have PHP error reporting turned on!
Useful Bits
PHPUnit documentation
Checking that PEAR works
pear config-show
pear config-set [key] [path]
pear upgrade PEAR