2

I'm After reading other similar posts I felt I've followed everything to the letter, hence my confusion and this post:

I'm running: - Windows 7 64bit - Wamp Server 2.0 with php 5.2.5

I'm reading the packt Agile Web Development with Yii and PHP5

Actions so far:

  1. Installed PEAR in c:\wamp\bin\php5.2.5\PEAR\pear (it created a subfolder inside 'PEAR')
  2. Installed and Setup Selenium RC
  3. Added the PEAR_ENV.reg file for Environment Variables
  4. Restarted and Confirmed PEAR is working by typing 'pear' in command prompt (works in any subfolder as well)
  5. Installed PHPUnit via PEAR and confirmed 'phpunit' is working via command prompt. Tested phpunit with selenium for the Yii testcase at 'functional/SiteTest.php'
  6. changed and tested the include_path in both php.ini files (in the php5.2.5 folder and the apache folder) to 'c:\wamp\bin\php5.2.5\PEAR\pear'. Turns out both need to be the same for phpunit and pear to work (?)

The problem: the following command works when I type via command prompt:

cd c:\wamp\www\yiidemo\protected\tests
phpunit functional\SiteTest.php

phpunit works with selenium for testing the site with firefox.

But when I create an empty class for testing as stated in the book and run this:

phpunit unit\MessageTest.php

I get this:

"Warning: require(PHPUnit/Autoload.php): failed to open stream: No such file or directory in c:\wamp\www\yiidemo\protected\tests\unit\MessageTest.php"

But if I enter the unit folder and try the command:

phpunit MessageTest.php

I get an error message stating

"Fatal Error: Class 'CTestCase' not found in "c:\wamp\www\yiidemo\protected\tests\unit\MessageTest.php" on line 3

<?php 
class MessageTest extends CTestCase
    {

    }
?>

Any idea what I'm doing wrong. I've come a long way to this point and quite stuck since the command lines are working.

Audacitus
  • 125
  • 8
  • I decided to look for the physical Autoload.php file but couldn't find it. It turns out the phpunit installation via pear command line does not include this file compared to pulling phpunit from the [Github Site](https://github.com/sebastianbergmann/phpunit/). Even more frustrating is that the Autoload.php points to files also not included in the pear command install version, despite adding all dependencies 'code'(--alldeps) – Audacitus Sep 11 '12 at 16:36
  • 1
    Did that solve the problem? Then you can answer your own question and mark it as solved! :) – Narretz Sep 12 '12 at 09:49
  • ^ I'm glad I didn't read this when I was in the thick of it. But I'll post my findings further and when I do solve it I'll post something back for the community – Audacitus Sep 12 '12 at 17:03

1 Answers1

1

Update. Problem solved.

Detailed reasons why the problem persisted:

  • There was no Autoload.php file in the phpunit version I used, so copying the latest build from github and dumping it in the pear folder and tinkering from there didn't work with setup/install (missing references).

  • Even if I copied only the Autoload.php file from the github folder (to see what would happen), further missing references convinced me what Yii expected was far different from what I had installed.

  • PEAR unfortunately dictates WHICH VERSION of phpunit to install BASED ON YOUR PHP Version. Since I was using php5.2.5, the highest version of phpunit it would install was a version without Autoload.php, even if you used the --force --alldeps options

Moving Forward.

  • Upgrade your setup at least PHP5.3.4

  • run go-pear.phar in \path\to\php\php5.3.4 and accept default parameters

  • Add PEAR_ENV.reg to registry

  • install phpunit

  • install phpunit/selenium

NOTE to Wampserver users (IMPORTANT!!) Upgrade to ONLYwampserver 2.1, NOT 2.2! 2.2 doesn't seem to have its curl extension working, which poses a problem when installing phpunit selenium. Even with Wamp 2.1 (I was upgrading from 2.0), you have to manually enable curl extension in both php.ini files in the php and apache folders (As far as I tested PEAR uses PHP's php.ini while phpunit used the apache's php.ini).

Using WAMP 2.2 gave me "side by side" configuration error even on enabling curl via php.ini. See Link: Wamp Server 2.2 Windows 7 64-bit and curl not working side-by-side configuration incorrect

the curl extension is needed for installing Selenium for PHPUnit

Take all this into account and you shouldn't have a problem!

Audacitus
  • 125
  • 8
  • **My Closing thoughts** I honestly expected a much better experience. If one had to pour through a dozen sites to tackle so many issues that aren't obvious or even labelled as related, I think we can agree it can be better. – Audacitus Sep 12 '12 at 22:16
  • 1
    Thanks for the answer! The problem with these books is really that they cannot take into account every little change or bug in your dev stack. :( I actually had the problem with CURL and Wamp 2.2 too, and this is was worked for me: http://stackoverflow.com/questions/10939248/wamp-php-on-windows-7/10977022#10977022 – Narretz Sep 13 '12 at 14:44
  • While that is very true, I still feel the book should have done a better job. For something so intricate as PEAR dictating which phpUnit version is downloaded how does someone new start to figure that is the stumbling block? I read the first book before this (OOP with PHP5, Packt) and had no problem setting up testing/following. I just felt like they skipped out on it where they shouldn't have for the sake of skipping. – Audacitus Sep 13 '12 at 19:27