PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Testing » PHPUnit2 » Bug #5282

Tests get run 3 times

Details

Submitted2005-09-02 17:06 UTC
Fromjeff dot sawatzky at niltzdesigns dot com
Assignedsebastian
StatusBogus
PackagePHPUnit2
PHP Version5.0.4
OSlinux
Roadmaps(Not assigned)

Comments

[2005-09-02 17:06 UTC] jeff dot sawatzky at niltzdesigns dot com

Description:
------------
using PHPUnit2 version 2.2.1

I have 4 classes (Date, Time, DateTime and TimeSpan)

I have 4 test classes (DateTest, TimeTest, DateTimeTest, TimeSpanTest) that have tests that test the methods on the respective classes. DateTest has 5 tests, TimeTest has 5 tests, DateTimeTest has 8 tests, and TimeSpanTest has 6 tests totalling 24 tests all together.

I then have a TestSuite class defined (shown in the test script section below). When I run

When I run $phpunit TestSuite everything runs fine, except the fact that it runs all the tests 3 times resulting in 72 tests being run total.

Test script:
---------------
<?php
require_once "PHPUnit2/Framework/TestSuite.php";

/**
* Test suite class.
*/
class TestSuite extends PHPUnit2_Framework_TestSuite {

public function __construct()
{
parent::__construct();

//add the time class tests to the suite
require_once "time_test.php";
$this->addTestSuite("TimeTest");

//add the date class tests to the suite
require_once "date_test.php";
$this->addTestSuite("DateTest");

//add the datetime class tests to the suite
require_once "datetime_test.php";
$this->addTestSuite("DateTimeTest");

//add the timespan class tests to the suite
require_once "timespan_test.php";
$this->addTestSuite("TimeSpanTest");
}
}
?>

Expected result:
----------------
PHPUnit 2.2.1 by Sebastian Bergmann.

.........................................
...............................

Time: 0.10421204566956

OK (24 tests)

Actual result:
--------------
PHPUnit 2.2.1 by Sebastian Bergmann.

.........................................
...............................

Time: 0.10421204566956

OK (72 tests)

[2005-10-15 07:53 UTC] sebastian at php dot net

I was able to reproduce this issue but have not found a fix yet.

You should circumvent this issue by setting up your TestSuite object in a more standard way (look at http://cvs.php.net/pear/PHPUnit2/Tests/ for an example of how to organize a test suite with PHPUnit2). The way you're doing it is not encouraged (nor supported at this time).

[2005-12-31 07:28 UTC] sebastian at php dot net

Assume we have the following two sourcefiles:

FooSuite.php
<?php
require_once 'FooTest.php';

class FooSuite extends PHPUnit2_Framework_TestSuite {
public function __construct() {
parent::__construct();

$this->addTestSuite('TimeTest');
}
}
?>

FooTest.php
<?php
class FooTest extends PHPUnit2_Framework_TestCase {
public function testSomething() {
$this->assertEquals(TRUE, FALSE);
}
}
?>

Running PHPUnit results in

$ phpunit FooSuite
PHPUnit 3.0.0-dev by Sebastian Bergmann.



Time: 00:00

OK (0 tests)

and

PHPUnit 3.0.0-dev by Sebastian Bergmann.

F

Time: 00:00
There was 1 failure:
1) testSomething(FooTest)
failed asserting that <false> is equal to <boolean:true>
expected bool <true>
got bool <false>
/home/sb/FooTest.php:4

FAILURES!
Tests: 1, Failures: 1.

You need to change the FooSuite class as follows

FooSuite.php
<?php
require_once 'FooTest.php';

class FooSuite {
public static function suite() {
$suite = new PHPUnit2_Framework_TestSuite;
$suite->addTestSuite('FooTest');

return $suite;
}
}
?>

to achieve what you want

$ phpunit FooSuite
PHPUnit 3.0.0-dev by Sebastian Bergmann.

F

Time: 00:00
There was 1 failure:
1) testSomething(FooTest)
failed asserting that <false> is equal to <boolean:true>
expected bool <true>
got bool <false>
/home/sb/FooTest.php:4

FAILURES!
Tests: 1, Failures: 1.