PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: February 27, 2013 06:13AM

Hi Everyone,

I am doing a tutorial on using the PHP framework called Yii with PHP and MySQL. Now in this tutorial they tell you to install the PHPUnit component/extension which apparently tightly integrates with PHP. Now PHP on my Windows XP machine is part of WampServer and was installed as such. PHP is not a standalone installation.

So how do I now install this PHPUnit component/extension so that it becomes part of WampServer but will at the same time be available in my phpDesigner IDE and also on the Windows XP command line. They talk about using the PEAR installer to achieve this if your PHP installation was done seperatlely. But as mentioned, mine is part of WampServer.

So before I jump in and use the PEAR installer as suggested by the tutorial, I thought of first asking the WampServer forum of the correct way to approach this.

Regards and thank you in advance



Edited 1 time(s). Last edit at 02/27/2013 06:17AM by Gert Myburgh.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: February 27, 2013 01:59PM

Well basically where they talk about C:\php you should use c:\wamp\bin\php\phpx.y.z where x.y.z is the php version you are using.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.MET002-INTERNET-CPE.ensync.net)
Date: February 27, 2013 03:26PM

Thank you RiggsFolly.

So I take it that I have to follow the PEAR PHPUnit installation procedure and just take note of your suggestion about where PHP is installed.

Ok. Just wanted to make sure that there is no plug-in for WampServer which will enable the PHPUnit for me.

Thanks anyway for the advice.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: RiggsFolly (---.ppp.as43234.net)
Date: February 27, 2013 04:52PM

Depending on which version of PHP you are using you may find that PEAR or rather go-pear.bat or go-pear.phar is not where it is suggested it should be or in fact nowhere to be found.

If this happens to you, you can download the go-pear.phar ( modern replacement for go-pear.bat ) from here

http://pear.php.net/go-pear.phar

Just enter that address in the browser of your choice and it should download that file and ask you to save it. Save it to the phpx.y.z folder.
create a new folder under the phpx.y.z folder called PEAR.

Then instead of running go-pear.bat you run > php go-pear.phar
and it will install the pear manager for you and you will be all PEAR'd up.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.umts.vodacom.co.za)
Date: February 27, 2013 09:46PM

Thank you RiggsFolly.

Your help is very much appreciated.

Keep well.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: February 28, 2013 06:41AM

Hi RiggsFolly or anybody else that can help me.

PHP DIR = C:\wamp\bin\php\php5.3.1
PEAR DIR = C:\wamp\bin\php\php5.3.1\pear

I followed the advice above to install PEAR on my machine. It seems to be successfull and when I ran on my Windows XP commandline the 'pear', 'pear version' and 'pear config-get php_dir' commands then I get the desired results but ....

when I ran:
C:\wamp\bin\php\php5.3.1>php --ini

I get"
Configuration File (php.ini) Path: C:\WINDOWS
Loaded Configuration File: C:\wamp\bin\php\php5.3.1\php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)

Now where on earth is it getting the information that my PHP.INI is in C:\WINDOWS ? I looked in C:\WINDOWS and there is no PHP.INI in that folder.

Then when I create the following file:
Location = [localhost]

Content =
<?php
require_once 'System.php';
var_dump(class_exists('System', false));
?>

then I get:
Warning: require_once(System.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\check_pear.php on line 2 (see my check_pear.php content above)

Fatal error: require_once() [function.require]: Failed opening required 'System.php' (include_path='.;C:\php5\pear') in C:\wamp\www\check_pear.php on line 2 (see my check_pear.php content above)

Now again, where on earth is it getting the information that my include path for PEAR is C:\php5\pear ? I looked in C:\ and there is no php5 folder.

I even search through C:\wamp\bin\php\php5.3.1 for the string 'C:\php5\pear' and it does not appear in any file. I also checked the files in any subfolders under C:\wamp\bin\php\php5.3.1

Thanks in advance.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: RiggsFolly (---.as13285.net)
Date: February 28, 2013 10:10AM

RE: php --ini

PHP has a default search path when looking for its ini file C:\WINDOWS is one of the places it looks
If you notice the next line say 'I found one in C:\wamp\bin\php\php5.3.1\php.ini ' it does not say it found one in C:\WINDOWS

So dont worry about that.


RE:Fatal error finding system.php

You missed or your tutorial missed a step. You need to edit your php.ini in C:\wamp\bin\php\php5.3.1\php.ini
there is a commented out parameter called 'include_path' it looks like this

;include_path = ".;C:\php\PEAR"

You need to change that so the new PEAR folder is used and not the C:\php\PEAR folder

So it should look like this -

include_path = ".;c:\wamp\bin\php\php5.3.17\PEAR"

That script ( system.php ) is located in the PEAR folder and currently your config does not tell PHP that it should look in there when attempting to resolve include and require statements.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: March 01, 2013 05:06AM

Hi RiggsFolly,

Thank you for your prompt reply.

I could swear that I or the PEAR installer has made that change in the PHP.INI but let me have a look again. Might have missed that step.

Thanks so far for all your help.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: March 01, 2013 07:32PM

Hi RiggsFolly,

The entry below appears in my PHP.INI (in C:\wamp\bin\php\php5.3.1) so I am now a bit confused. (see problem above)

;***** Added by go-pear
include_path=".;C:\wamp\bin\php\php5.3.1\pear"
;*****

I confirmed that the folder exists and 'System.php' does appear in 'C:\wamp\bin\php\php5.3.1\pear'

Maybe I should remove the '.;' in the beginning and try again.

Thank you for any advice you might have.

Gert Myburgh

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: stevenmartin99 (Moderator)
Date: March 01, 2013 07:53PM

wrong php.ini


left click wamp icon> php> php.ini

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: March 01, 2013 10:13PM

Hi stevenmartin99 ,

Thank you. You are 100% correct.

I was looking at C:\wamp\bin\php\php5.3.1\php.ini and I should have been looking at C:\wamp\bin\apache\Apache2.2.9\bin\php.ini.

Does that mean I have to reinstall PEAR again and this time point to the correct PHP.INI or can I just insert include_path=".;C:\wamp\bin\php\php5.3.1\pear" into the correct PHP.INI ? Not sure if PEAR INSTALLER make some other configuration file changes.

Regards and thank you in advance.

Gert Myburgh

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: RiggsFolly (---.as13285.net)
Date: March 01, 2013 11:00PM

No you should be ok as you are.

In fact you should keep both of those PHP.INI files updated, The one in apache is for the website, the one in the php folder is used if you use PHPCLI, i.e. php from the command line

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: March 02, 2013 10:56PM

Ok thank you for all the advice and help. When this is sorted then all thats left is installing PHPUnit using PEAR and hopefully that will go without any problems.

Regards until next time.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: March 05, 2013 06:47AM

Hi Everyone,

I tried to find a forum for PHPUnit but could not yet find one so I decided to come back here.

I succeeded with installing PEAR and when I installed PHPUnit using the PEAR installer it seems to have installed ok but however there seems to be a small hick-up.

Folder I am in = C:\wamp\www\trackstar\protected\tests>

When I try to execute the command below on my Windows XP machine's command line:
>phpunit unit/DbTest.php

I get:
'phpunit' is not recognized as an internal or external command, operable program or batch file.

Question: Do I have to update my Windows path somehow. Nowhere in the PHPUnit installation instructions is it stating that I have to update my path.

I could not find a 'phpunit.exe' file but i did find a 'phpunit.php' file under the PEAR folder (C:\wamp\bin\php\php5.4.3\PEAR).

Regards and thank you for any suggestions.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: stevenmartin99 (Moderator)
Date: March 05, 2013 07:34AM

If there is not phpunit.exe then that won't work

In the command line navigate to the php folder

C:/wamp/bin/php/php5.4.3

Make sure u have edited the php.ini in that folder as now u want to use the command line which uses that php.ini and not apaches.


Type in

php C:/wamp/bin/php/php5.4.3/phpunit.php unit/dbtest.php

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: RiggsFolly (---.as13285.net)
Date: March 05, 2013 10:27AM

My suggestion would be to create a little batch file ( .bat or .cmd ) called something like phppath.cmd

this is what it should look like
>echo off
>set path=%PATH%;c:\wamp\bin\php\php5.4.3
>php -v


put this in a folder that is already on the PATH so you can run it from anywhere

Then whenever you use a command window ( dos window ) and you want to use PHPCLI you run that batch file and it set php to be on your path.
It will also (php -v) display the php version so you now it has found php on the path

So to run a php script you would do this:

>phppath
then
>php xyz.php to run a php script

and its good for the duration of the existance of that dos window ( only need to do it once )

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: March 05, 2013 07:29PM

Thank you once again for the quick response.

Let me quickly try the suggestions.

Options: ReplyQuote
Re: PHP Unit Testing on WampServer
Posted by: Gert Myburgh (---.telkomadsl.co.za)
Date: March 10, 2013 08:03PM

Hi RiggsFolly and stevenmartin99,

I kind of sorted this whole issue with PEAR, PHPUnit and WAMPServer out.

I say kind of because after following your advice and after some further investigation and tweaking I got everything running from the command line. PEAR was now working and PHPUnit was also now working and I got the desired results as set out in the Yii PHP framework tutorial. But.....

My phpDesigner IDE was now broken. It picked up the PHP.EXE and PHP.INI from the path that was now set for PHPUnit and complained about a few objects that it could not find that is suppose to be in php5ts.dll.

After I removed the path that I added to get PHPUnit working, suddenly my phpDesigner IDE works again. I have already reported this to the support department of phpDesigner and they are now looking into it.

A big thank you to you guys for helping me sorting out PEAR and PHPUnit.

Regards,

Gert Myburgh



Edited 1 time(s). Last edit at 03/10/2013 08:05PM by Gert Myburgh.

Options: ReplyQuote


Sorry, only registered users may post in this forum.