installing phpunit

General discussion on Zend Server for IBM System i
Post Reply
peter_connell
Posts: 4
Joined: Wed May 04, 2011 4:17 am

installing phpunit

Post by peter_connell » Sat Sep 06, 2014 11:07 pm

I like using the zf command from qp2term to create controllers etc
I’m intrigued to know what actions would be generated if PHPUnit was working instead of getting the message
“PHPUnit is required in order to generate controller test stubs”

After a bit of googling I’ve downloaded the latest phpunit-4.2.5.phar from https://phar.phpunit.de into /usr/local/zendsvr/bin
And followed some instruction I founds that says to install it by running
php phpunit-4.2.5.phar

But nothing actually appears to be installed as far as I can see.
Any ideas?

adam8525
Posts: 3
Joined: Fri Jan 10, 2014 5:34 pm

Re: installing phpunit

Post by adam8525 » Wed Sep 17, 2014 2:20 pm

If PHPUnit is installed then you should be able to do the following:

1. Start the shell with CALL QP2TERM.
2. Add /usr/local/zendsvr/bin to your include path with PATH=$PATH:/usr/local/zendsvr/bin (Note: if you are running Zend Server 6 or 7 then the path should be /usr/local/zendsvr6/bin).
3. Type phpunit --version. You should get a message informing you of which version you have installed.

At this point PHPUnit should be working.

User avatar
clarkphp
Zend Global Services
Posts: 34
Joined: Sat Jun 30, 2012 9:59 pm
Location: United States
Contact:

Re: installing phpunit

Post by clarkphp » Fri Sep 19, 2014 2:05 pm

The phpunit.phar has files internally which have shebangs pointing to /usr/env/php which currently isn't set up apparently. I got PHPUnit running on the IBM in order to submit some DB2 fixes for ZF2.

I installed and used Composer to do this. If you need to test ZF1 code, you need an old version of PHPUnit, I think 3.4.15, if I recall correctly. I can help with that if that is the case. These instructions here are for current versions of PHPUnit.

1. When running PHP scripts from the command line on the IBM, always use "php-cli" - do not use "php" alone.

2. Make it easy to run PHP in CLI mode, so you don't have to specify the full path to php each time.
edit /home/YOUR_PROFILE_NAME/.profile to include the following lines:
PATH=/usr/local/zendsvr6/bin:$PATH
export PATH

3. Install Composer
a. Change to the directory where you want to install composer. Your home directory is fine.
$ cd ~
b. Install Composer into the current directory
$ php-cli -r "readfile('https://getcomposer.org/installer');" | php-cli
c. Rename phar file for less typing (this is a common convention for PHAR archives)
$ mv composer.phar composer
d. To get cleaner screen output, *always* run Composer on the IBM with --no-ansi option. Compare the following command, for example, with and without the --no-ansi option:
$ php-cli composer --no-ansi list

4. Install PHPUnit into a project via Composer
a. Edit the project's composer.json file and add PHPUnit as a dependency:
{
"require-dev": {
"phpunit/phpunit": "4.2.*"
}
}
b. php-cli ~/composer --no-ansi install

For more info on Composer, the package manager for PHP, visit https://getcomposer.org/
For more info on PHPUnit, the de facto unit testing framework for PHP, visit https://phpunit.de/

Any questions, just yell :-)
Clark

Post Reply