0

I am having a hard time trying making PHPUnit work. My Directory is for php is C:/wamp/bin/php/php5.4.3 Now, I read PHPUnit does not work without PEAR, so I got the go-pear.phar file and placed it in C:/wamp/bin/php/php5.4.3/PEAR/ ran the go-pear.phar file and installed in on the system. third, I installed PHPUnit using Git Bash and put it in C:/wamp/www/local/unit-testing/ (Not sure if the directories are correct)

Now, I created a simple UserTest file

<?php
require_once "phpunit/PHPUnit/Autoload.php";
require_once "User.php";
class UserTest extends PHPUnit_Framework_TestCase
{
     protected $user;

    // test the talk method
    protected function setUp() {
        $this->user = new User();
        $this->user->setName("Tom");
    }

    protected function tearDown() {
        unset($this->user);
    }

 public function testTalk() {
        $expected = "Hello world!";
        $actual = $this->user->talk();
        $this->assertEquals($expected, $actual);
    }

}

And tried to require this file and run it from the command line in Windows. But, due to lack of instructions on where this files should exactly be, I can't seem to run it.

As of now the problem is command line does not recognize the PEAR command. Even though, I had run PEAR_ENV.reg file to add PATH variables to the file.

secondly, I am not sure where exactly PEAR & PHPUnit should be installed in my current structure. I keep all my php pages/project in C:/wamp/www/local/<-- I need to test files in this directory.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
  • If I were you, I'd install Linux as a development evnironment (e.g. as a secondary system), then type few command lines to install pear, pecl, phpunit and all other tools. This would probably take much less time than fighting with Windows. – takeshin Aug 02 '13 at 14:04
  • Did you get a satisfactory answer from anyone to accept, or is there still issues with the suggestions? – Steven Scott Nov 14 '13 at 22:58

1 Answers1

1

The PHPUnit batch file should be in your path. Then running PHPUnit from the command line would be done in a shell, with the current directory being where you have installed everything, and it assumes that your User.php file is there as well.

I sue a bootstrap.php file to run from my source code directory.

<?php
/**
 * This file is used to configure the basic environment for testing in PHPUnit.
 */

// PHP and Web server settings
error_reporting(E_ALL | E_STRICT);
date_default_timezone_set("America/Toronto");       // Set the default timezone
$_SERVER['SERVER_NAME'] = 'http://xxx';       // Set Web Server name

// Process the Include Path to allow the additional applications to be set.
$IncludePaths = explode( PATH_SEPARATOR, get_include_path() );
$NewIncludePaths = array_merge( $IncludePaths, array(dirname(__FILE__) ));
set_include_path( implode( PATH_SEPARATOR, array_unique($NewIncludePaths)));    // Update Include Path

//define('PHPUNIT_RUNNING', 1); // Indicate to the code that Automated Testing is running.
?>

I was able to follow the PEAR Installation Instructions for PHPUnit and get things up and running once the directory where PHPUnit.bat existed was in my DOS Path.

Steven Scott
  • 10,234
  • 9
  • 69
  • 117