Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit error - Class could not be found

Tags:

php

phpunit

I just installed PHPUnit 3.5 on my system, upgrading it from 3.4, and I'm having some trouble with the new version. When I try to run a test, I always get the same output. Here's what I get when I try to run on the command line the StackTest example from the PHPUnit manual, example 4.1:

> phpunit StackTest

X-Powered-By: PHP/5.2.17
Content-type: text/html

PHPUnit 3.5.13 by Sebastian Bergmann.

Class StackTest could not be found in StackTest.php.

Worse yet, when I try to run it from a web browser, I get the following output:

Fatal error: Class 'PHPUnit_Framework_TestCase' not found in /path/to/tests/StackTest.php on line 2 

Does anyone know how to set this up? Thanks.

like image 471
jay Avatar asked May 13 '11 19:05

jay


2 Answers

I had the problem you described on Windows. The problem was in the file pear\PHPUnit\Runner\StandardTestSuiteLoader.php on line 131 an it was caused by different drive letter case in file name in the condition

if ($class->getFileName() == realpath($suiteClassFile)) {

My simple fix is to change this line to be case insensitive

if (strtolower($class->getFileName()) == strtolower(realpath($suiteClassFile))) {
like image 123
Miraz Avatar answered Sep 20 '22 02:09

Miraz


phpunit MyTestClass

In my case

  • MyTestClass.php should be in the project home directory
  • it should starts with long php open tag (<?php, not <?)
  • it should contain class MyTestClass extends PHPUnit_Framework_TestCase {

I know this is most likely not the best way, just point for a beginner to start with.

like image 36
Putnik Avatar answered Sep 20 '22 02:09

Putnik