Source for file TestSuite.php
Documentation is available at TestSuite.php
// +------------------------------------------------------------------------+
// +------------------------------------------------------------------------+
// | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// $Id: TestSuite.php,v 1.6 2004/05/26 06:24:05 sebastian Exp $
require_once 'PHPUnit2/Framework/Test.php';
require_once 'PHPUnit2/Framework/TestCase.php';
require_once 'PHPUnit2/Framework/Warning.php';
* A TestSuite is a composite of Tests. It runs a collection of test cases.
* Here is an example using the dynamic test definition.
* $suite = new PHPUnit2_Framework_TestSuite;
* $suite->addTest(new MathTest('testPass'));
* Alternatively, a TestSuite can extract the tests to be run automatically.
* To do so you pass a ReflectionClass instance for your
* PHPUnit2_Framework_TestCase class to the PHPUnit2_Framework_TestSuite
* $suite = new PHPUnit2_Framework_TestSuite(
* new ReflectionClass('MathTest')
* This constructor creates a suite with all the methods starting with
* "test" that take no arguments.
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright Copyright © 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
* The name of the test suite.
* The tests in the test suite.
private $tests = array ();
// {{{ public function __construct($theClass = '', $name = '')
* Constructs a new TestSuite:
* - PHPUnit2_Framework_TestSuite() constructs an empty TestSuite.
* - PHPUnit2_Framework_TestSuite(ReflectionClass) constructs a
* TestSuite from the given class.
* - PHPUnit2_Framework_TestSuite(ReflectionClass, String)
* constructs a TestSuite from the given class with the given
* - PHPUnit2_Framework_TestSuite(String) either constructs a
* TestSuite from the given class (if the passed string is the
* name of an existing class) or constructs an empty TestSuite
public function __construct($theClass = '', $name = '') {
$theClass = new ReflectionClass ($theClass);
$constructor = $theClass->getConstructor ();
if ($constructor === NULL ||
!$constructor->isPublic ()) {
'Class %s has no public constructor',
$methods = $theClass->getMethods ();
foreach ($methods as $method) {
$this->addTestMethod ($method, $names, $theClass);
if (empty ($this->tests)) {
// {{{ public function toString()
* Returns a string representation of the test suite.
// {{{ public function addTest(PHPUnit2_Framework_Test $test)
* Adds a test to the suite.
* @param PHPUnit2_Framework_Test
// {{{ public function addTestSuite($testClass)
* Adds the tests from the given class to the suite.
* @param mixed $testClass
$testClass = new ReflectionClass ($testClass);
$testClass instanceof ReflectionClass ) {
// {{{ public function countTestCases()
* Counts the number of test cases that will be run by this test.
foreach ($this->tests as $test) {
$count += $test->countTestCases ();
// {{{ public static function createTest(ReflectionClass $theClass, $name)
* @param ReflectionClass $theClass
* @return PHPUnit2_Framework_Test
public static function createTest(ReflectionClass $theClass, $name) {
$test = $theClass->newInstance ();
'Cannot instantiate test case: %s',
// {{{ protected function createResult()
* Creates a default TestResult object.
* @return PHPUnit2_Framework_TestResult
// {{{ public function getName()
* Returns the name of the suite.
// {{{ public function run($result = null)
* Runs the tests and collects their result in a TestResult.
* @param PHPUnit2_Framework_TestResult $result
* @return PHPUnit2_Framework_TestResult
public function run($result = null ) {
// XXX: Workaround for missing optional class type hints.
'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.'
foreach ($this->tests as $test) {
if ($result->shouldStop ()) {
// {{{ public function runTest(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_TestResult $result)
* @param PHPUnit2_Framework_Test $test
* @param PHPUnit2_Framework_TestResult $testResult
public function runTest(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_TestResult $result) {
// {{{ public function setName($name)
* Sets the name of the suite.
// {{{ public function testAt($index)
* Returns the test at the given index.
* @return PHPUnit2_Framework_Test
public function testAt($index) {
if (isset ($this->tests[$index])) {
return $this->tests[$index];
// {{{ public function testCount()
* Returns the number of tests in this suite.
// {{{ public function tests()
* Returns the tests as an enumeration.
public function tests() {
// {{{ public function addTestMethod(ReflectionMethod $method, &$names, ReflectionClass $theClass)
* @param ReflectionMethod $method
* @param ReflectionClass $theClass
private function addTestMethod (ReflectionMethod $method, &$names, ReflectionClass $theClass) {
$name = $method->getName ();
if ($this->isPublicTestMethod ($method)) {
else if ($this->isTestMethod ($method)) {
'Test method is not public: %s',
// {{{ private function isPublicTestMethod(ReflectionMethod $method)
* @param ReflectionMethod $method
private function isPublicTestMethod (ReflectionMethod $method) {
return ($this->isTestMethod ($method) &&
// {{{ private function isTestMethod(ReflectionMethod $method)
* @param ReflectionMethod $method
private function isTestMethod (ReflectionMethod $method) {
return (substr($method->name , 0 , 4 ) == 'test');
// {{{ private static function warning($message)
* @return PHPUnit2_Framework_Warning
private static function warning ($message) {
* vim600: et sw=2 ts=2 fdm=marker
Documentation generated on Mon, 11 Mar 2019 13:55:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|