class TestSuite implements Test, SelfDescribing, IteratorAggregate (View source)

A TestSuite is a composite of Tests. It runs a collection of test cases.

Properties

protected bool $backupGlobals Enable or disable the backup and restoration of the $GLOBALS array.
protected bool $backupStaticAttributes Enable or disable the backup and restoration of static attributes.
protected bool $runTestInSeparateProcess
protected string $name The name of the test suite.
protected array $groups The test groups of the test suite.
protected TestCase[] $tests The tests in the test suite.
protected int $numTests The number of tests in the test suite.
protected bool $testCase
protected array $foundClasses

Methods

__construct(mixed $theClass = '', string $name = '')

Constructs a new TestSuite:

string
toString()

Returns a string representation of the test suite.

addTest(Test $test, array $groups = [])

Adds a test to the suite.

addTestSuite(mixed $testClass)

Adds the tests from the given class to the suite.

addTestFile(string $filename)

Wraps both addTest() and addTestSuite as well as the separate import statements for the user's convenience.

addTestFiles(array|Iterator $filenames)

Wrapper for addTestFile() that adds multiple test files.

int
count(bool $preferCache = false)

Counts the number of test cases that will be run by this test.

static Test
createTest(ReflectionClass $theClass, string $name)

No description

createResult()

Creates a default TestResult object.

string
getName()

Returns the name of the suite.

array
getGroups()

Returns the test groups of the suite.

getGroupDetails()

No description

setGroupDetails(array $groups)

Set tests groups of the test case

run(TestResult $result = null)

Runs the tests and collects their result in a TestResult.

setRunTestInSeparateProcess(bool $runTestInSeparateProcess)

No description

runTest(Test $test, TestResult $result) deprecated

Runs a test.

setName(string $name)

Sets the name of the suite.

Test|false
testAt(int|false $index)

Returns the test at the given index.

array
tests()

Returns the tests as an enumeration.

setTests(array $tests)

Set tests of the test suite

markTestSuiteSkipped(string $message = '')

Mark the test suite as skipped.

addTestMethod(ReflectionClass $class, ReflectionMethod $method)

No description

static bool
isTestMethod(ReflectionMethod $method)

No description

static WarningTestCase
warning(string $message)

No description

static SkippedTestCase
skipTest(string $class, string $methodName, string $message)

No description

incompleteTest(string $class, string $methodName, string $message)

No description

setbeStrictAboutChangesToGlobalState(bool $beStrictAboutChangesToGlobalState)

No description

setBackupGlobals(bool $backupGlobals)

No description

setBackupStaticAttributes(bool $backupStaticAttributes)

No description

getIterator()

Returns an iterator for this test suite.

injectFilter(Factory $filter)

No description

setUp()

Template Method that is called before the tests of this test suite are run.

tearDown()

Template Method that is called after the tests of this test suite have finished running.

Details

__construct(mixed $theClass = '', string $name = '')

Constructs a new TestSuite:

  • PHPUnit\Framework\TestSuite() constructs an empty TestSuite.

    • PHPUnit\Framework\TestSuite(ReflectionClass) constructs a TestSuite from the given class.

    • PHPUnit\Framework\TestSuite(ReflectionClass, String) constructs a TestSuite from the given class with the given name.

    • PHPUnit\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 with the given name.

Parameters

mixed $theClass
string $name

Exceptions

Exception

string toString()

Returns a string representation of the test suite.

Return Value

string

addTest(Test $test, array $groups = [])

Adds a test to the suite.

Parameters

Test $test
array $groups

addTestSuite(mixed $testClass)

Adds the tests from the given class to the suite.

Parameters

mixed $testClass

Exceptions

Exception

addTestFile(string $filename)

Wraps both addTest() and addTestSuite as well as the separate import statements for the user's convenience.

If the named file cannot be read or there are no new tests that can be added, a PHPUnit\Framework\WarningTestCase will be created instead, leaving the current test run untouched.

Parameters

string $filename

Exceptions

Exception

addTestFiles(array|Iterator $filenames)

Wrapper for addTestFile() that adds multiple test files.

Parameters

array|Iterator $filenames

Exceptions

Exception

int count(bool $preferCache = false)

Counts the number of test cases that will be run by this test.

Parameters

bool $preferCache Indicates if cache is preferred.

Return Value

int

static Test createTest(ReflectionClass $theClass, string $name)

Parameters

ReflectionClass $theClass
string $name

Return Value

Test

Exceptions

Exception

protected TestResult createResult()

Creates a default TestResult object.

Return Value

TestResult

string getName()

Returns the name of the suite.

Return Value

string

array getGroups()

Returns the test groups of the suite.

Return Value

array

getGroupDetails()

setGroupDetails(array $groups)

Set tests groups of the test case

Parameters

array $groups

TestResult run(TestResult $result = null)

Runs the tests and collects their result in a TestResult.

Parameters

TestResult $result

Return Value

TestResult

setRunTestInSeparateProcess(bool $runTestInSeparateProcess)

Parameters

bool $runTestInSeparateProcess

Exceptions

Exception

runTest(Test $test, TestResult $result) deprecated

deprecated

Runs a test.

Parameters

Test $test
TestResult $result

setName(string $name)

Sets the name of the suite.

Parameters

string $name

Test|false testAt(int|false $index)

Returns the test at the given index.

Parameters

int|false $index

Return Value

Test|false

array tests()

Returns the tests as an enumeration.

Return Value

array

setTests(array $tests)

Set tests of the test suite

Parameters

array $tests

markTestSuiteSkipped(string $message = '')

Mark the test suite as skipped.

Parameters

string $message

Exceptions

SkippedTestSuiteError

protected addTestMethod(ReflectionClass $class, ReflectionMethod $method)

Parameters

ReflectionClass $class
ReflectionMethod $method

static bool isTestMethod(ReflectionMethod $method)

Parameters

ReflectionMethod $method

Return Value

bool

static protected WarningTestCase warning(string $message)

Parameters

string $message

Return Value

WarningTestCase

static protected SkippedTestCase skipTest(string $class, string $methodName, string $message)

Parameters

string $class
string $methodName
string $message

Return Value

SkippedTestCase

static protected IncompleteTestCase incompleteTest(string $class, string $methodName, string $message)

Parameters

string $class
string $methodName
string $message

Return Value

IncompleteTestCase

setbeStrictAboutChangesToGlobalState(bool $beStrictAboutChangesToGlobalState)

Parameters

bool $beStrictAboutChangesToGlobalState

setBackupGlobals(bool $backupGlobals)

Parameters

bool $backupGlobals

setBackupStaticAttributes(bool $backupStaticAttributes)

Parameters

bool $backupStaticAttributes

TestSuiteIterator getIterator()

Returns an iterator for this test suite.

Return Value

TestSuiteIterator

injectFilter(Factory $filter)

Parameters

Factory $filter

protected setUp()

Template Method that is called before the tests of this test suite are run.

protected tearDown()

Template Method that is called after the tests of this test suite have finished running.