As promised, here’s a quick guide that will allow you to prepare for my “Test your code like a pro – PHPUnit in practice” tutorial at PHPNW12 conference in Manchester on 5th October. If you still haven’t decided whether to go or not have a look at the official abstract and my previous blog posts. There is still time to get the tickets!
There are really 2 things that you will need, to get smoothly through the tutorial: git client and working installation of PHPUnit. So please make sure you have installed them and you can use them. Being able to open PDF files is also recommended as I will be giving out a tutorial’s manual/instructions in a PDF format.
Well this above obviously requires a computer. I guess you will decide to bring a laptop with you, although if you prefer to take your desktop computer with you, it will do too. While most of the stuff will be in the PDF file, going through the tutorial without a laptop will be difficult to follow and you will not learn as much. I will not have any spare laptops to borrow, sorry.
I strongly discourage brining in a Windows machine with you, unless you feel comfortable with solving any problems related with php, pear and PHPUnit in a very short period of time or you come really well prepared. We will not have a lot of time to spend configuring each other machines and we also don’t want the others to wait and do nothing while you set everything up. We only have 3 hours, and believe me it will go fast.
Using apt to install git should set you up pretty quickly. Just type in the below:
$ sudo apt-get install git-core $ git --version
You will need at least PHP 5.3.3 installed, but I strongly recommend installing PHP 5.4. Again with apt it should be pretty instant to get you set up:
$ sudo apt-get install php5-cli $ sudo apt-get install php-pear $ sudo apt-get install php5-xdebug $ php -v
Before you can install PHPUnit you need to make sure PEAR is at the latest version. So upgrade it first
$ sudo pear upgrade PEAR
Then finally you will be able to install PHPUnit:
$ sudo pear config-set auto_discover 1 $ sudo pear install pear.phpunit.de/PHPUnit $ phpunit --version
You can install git client on a Windows machine by using the installer package that you can download from msysgit project downloads page.
Just accept all the default options. All you really need is to be able to clone a repo and change branches.
- First download PHP 5.4 binaries from http://windows.php.net/ and unzip it into c:\php.
- Then download xdebug library from xdebug downloads page and copy it over to c:\php\ext directory.
- Rename the library to php_xdebug.dll.
- Copy c:\php\php.ini-development to c:\php\php.ini
- Make sure date.timezone is set to “Europe/London”
- Activate xdebug by adding the snippet bellow at the end of c:\php\php.ini
- Add c:\php to system path via Computer’s Advanced Properties -> Environment Variables
- Restart windows
- In the command prompt run:
c:\> php -v PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans
Next we have to install PEAR.
- Download go-pear.phar from http://pear.php.net and copy it over to c:\php\
- Run the following command and from the presented options change option 1 – Installation base to c:\php and option 11 – Name of configuration file to c:\php\pear.ini
- Then hit enter to finish installation
- Let installer change your include path at the end by answering y to the question “Would you like to alter php.ini?”
- Double-click the PEAR_ENV.reg file in c:\php
- Reboot again to make sure PEAR_ENV registry entries have taken effect
c:\> php c:\php\go-pear.phar
Finally it’s time to install PHPUnit. At this point just running the below should set you up.
c:\> pear config-set auto_discover 1 c:\> pear install pear.phpunit.de/PHPUnit c:\> phpunit --version PHPUnit 3.7.0 by Sebastian Bergmann.
I hope this short guide will let you come to my tutorial well prepared. I will see you in Manchester soon!