For those of you who haven't been following, this is a Windows installation. I'm attempting to install the latest and greatest PHPUnit3 (3.2.4 at the time of this writing). It seems that either no one cares about doing this on Windows or only really smart people who find it so simple that they didn't bother to write about it have ever done it. Because half way through writing this (after publishing it half-done), I searched for "installing phpunit on windows" and this very blog article came up on the 2nd page.
Nice going Google, but not very helpful.
Quick Summary
For the impatient, here's a quick summary of what I had to do. Afterwards is the detailed story of how I got to this. I assume you already have PHP installed in C:\php.
C:\php>go-pear.bat
- Merge C:\php\PEAR_ENV.reg
C:\php>pear channel-discover pear.phpunit.de
- Change
memory_limit
in php.ini to something high like 64M. (Remember the old setting.) - Save php.ini. Restart Apache.
C:\php>pear install --alldeps phpunit/PHPUnit
- Change
memory_limit
in php.ini back to what it was before. (The default is 8M I think.) - Save php.ini. Restart Apache.
Detailed Story
Now for the detailed story of how I got to the above steps.
- Install PEAR
I currently have PHP 5.2.3 installed, and I installed PEAR on 8 December 2007 getting the following output accepting the default options.C:\php>go-pear.bat
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] : system
Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.
1. Installation base ($prefix) : C:\php
2. Temporary directory for processing : C:\php\tmp
3. Temporary directory for downloads : C:\php\tmp
4. Binaries directory : C:\php
5. PHP code directory ($php_dir) : C:\php\pear
6. Documentation directory : C:\php\pear\docs
7. Data directory : C:\php\pear\data
8. Tests directory : C:\php\pear\tests
9. Name of configuration file : C:\WINDOWS\pear.ini
10. Path to CLI php.exe : C:\php\.
1-10, 'all' or Enter to continue:
Beginning install...
Configuration written to C:\WINDOWS\pear.ini...
Initialized registry...
Preparing to install...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.2.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.2.2.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.5.4.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.2.tar...
pear/PEAR can optionally use package "pear/XML_RPC" (version >= 1.4.0)
install ok: channel://pear.php.net/Archive_Tar-1.3.2
install ok: channel://pear.php.net/Console_Getopt-1.2.2
install ok: channel://pear.php.net/Structures_Graph-1.0.2
install ok: channel://pear.php.net/PEAR-1.5.4
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"
******************************************************************************
WARNING! The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<C:\php\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.
Would you like to alter php.ini <C:\php\php.ini>? [Y/n] : Y
php.ini <C:\php\php.ini> include_path updated.
Current include path : .
Configured directory : C:\php\pear
Currently used php.ini (guess) : C:\php\php.ini
Press Enter to continue:
** WARNING! Old version found at C:\php, please remove it or be sure to use the
new c:\php\pear.bat command
The 'pear' command is now at your service at c:\php\pear.bat
* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under C:\php\PEAR_ENV.reg .
This file creates ENV variables for the current user.
Double-click this file to add it to the current user registry.
Press any key to continue . . .
C:\php>
I then merged the PEAR_ENV.reg file as specified.
You should make sure that runningpear
at the command-line dumps a list of commands. - Install PHPUnitC:\php>pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded
C:\php>pear install phpunit/PHPUnit
Did not download optional dependencies: pear/Image_GraphViz, pear/Log, use --alldeps to download automatically
phpunit/PHPUnit can optionally use package "pear/Image_GraphViz" (version >= 1.2.1)
phpunit/PHPUnit can optionally use package "pear/Log"
phpunit/PHPUnit can optionally use PHP extension "pdo_sqlite"
phpunit/PHPUnit can optionally use PHP extension "xdebug" (version >= 2.0.0)
downloading PHPUnit-3.2.4.tgz ...
Starting to download PHPUnit-3.2.4.tgz (198,003 bytes)
.........................................done: 198,003 bytes
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 73 bytes) in C:\php\PEAR\PEAR\PackageFile\v2\Validator.php on line 1021
C:\php>
Now what?
Did it seriously run out of memory?
...I'll finish this post another day (tomorrow?), and hopefully I'll figure it out.
::day passes::
...Okay, I'm back. After checking my php.ini file, I found that the memory limit was indeed 8M. So I changedmemory_limit = 8Mtomemory_limit = 64M
Save, and restart Apache (necessary if you're running PHP as a module).
This time I decided to use the --alldeps option as indicated by my last run. If PHPUnit can use GraphViz to make pretty output, that would be great. So here goes another shot.C:\php>pear install --alldeps phpunit/PHPUnit
WARNING: "pear/DB" is deprecated in favor of "pear/MDB2"
phpunit/PHPUnit can optionally use PHP extension "pdo_sqlite"
phpunit/PHPUnit can optionally use PHP extension "xdebug" (version >= 2.0.0)
pear/Log can optionally use PHP extension "sqlite"
downloading PHPUnit-3.2.4.tgz ...
Starting to download PHPUnit-3.2.4.tgz (198,003 bytes)
.........................................done: 198,003 bytes
downloading Image_GraphViz-1.2.1.tgz ...
Starting to download Image_GraphViz-1.2.1.tgz (4,872 bytes)
...done: 4,872 bytes
downloading Log-1.9.11.tgz ...
Starting to download Log-1.9.11.tgz (38,479 bytes)
...done: 38,479 bytes
downloading DB-1.7.13.tgz ...
Starting to download DB-1.7.13.tgz (132,246 bytes)
...done: 132,246 bytes
downloading MDB2-2.4.1.tgz ...
Starting to download MDB2-2.4.1.tgz (119,790 bytes)
...done: 119,790 bytes
install ok: channel://pear.phpunit.de/PHPUnit-3.2.4
install ok: channel://pear.php.net/Image_GraphViz-1.2.1
install ok: channel://pear.php.net/Log-1.9.11
install ok: channel://pear.php.net/DB-1.7.13
install ok: channel://pear.php.net/MDB2-2.4.1
MDB2: Optional feature fbsql available (Frontbase SQL driver for MDB2)
MDB2: Optional feature ibase available (Interbase/Firebird driver for MDB2)
MDB2: Optional feature mysql available (MySQL driver for MDB2)
MDB2: Optional feature mysqli available (MySQLi driver for MDB2)
MDB2: Optional feature mssql available (MS SQL Server driver for MDB2)
MDB2: Optional feature oci8 available (Oracle driver for MDB2)
MDB2: Optional feature pgsql available (PostgreSQL driver for MDB2)
MDB2: Optional feature querysim available (Querysim driver for MDB2)
MDB2: Optional feature sqlite available (SQLite2 driver for MDB2)
To install use "pear install pear/MDB2#featurename"
C:\php>
It looks like it worked. :-)
Runphpunit
at the command-line to test that it worked. You should get a version and usage message dumped.
Change the memory limit back to 8M. Save, restart. - Test the Test Framework
To further test that my installation was actually working, I made a dummy test that always fails. Like so...<?php
require_once 'PHPUnit/Framework.php';
class DummyTest extends PHPUnit_Framework_TestCase {
public function testFail() {
$this->fail('Your test successfully failed!');
}
}
...and put it in my C:\ root directory as DummyTest.php. This way I can make sure my path is setup correctly to use PHPUnit from anywhere.
Sure enough, I get some good test-output.C:\>phpunit DummyTest
PHPUnit 3.2.4 by Sebastian Bergmann.
F
Time: 0 seconds
There was 1 failure:
1) testFail(DummyTest)
Your test successfully failed!
C:\DummyTest.php:7
FAILURES!
Tests: 1, Failures: 1.
C:\>