Class TestSuite
A class to contain test cases and run them with shared fixtures
Property Summary
-
$backupGlobals protected
boolEnable or disable the backup and restoration of the $GLOBALS array.
-
$backupStaticAttributes protected
boolEnable or disable the backup and restoration of static attributes.
-
$foundClasses protected
array -
$groups protected
arrayThe test groups of the test suite.
-
$name protected
stringThe name of the test suite.
-
$numTests protected
intThe number of tests in the test suite.
-
$runTestInSeparateProcess protected
bool -
$testCase protected
bool -
$tests protected
TestCase[]The tests in the test suite.
Method Summary
-
__construct() public
Constructs a new TestSuite:
-
addTest() public
Adds a test to the suite.
-
addTestDirectory() public
Adds all the files in a directory to the test suite. Does not recursive through directories.
-
addTestDirectoryRecursive() public
Recursively adds all the files in a directory to the test suite.
-
addTestFile() public
Wraps both
addTest()andaddTestSuiteas well as the separate import statements for the user's convenience. -
addTestFiles() public
Wrapper for addTestFile() that adds multiple test files.
-
addTestMethod() protected
-
addTestSuite() public
Adds the tests from the given class to the suite.
-
count() public
Counts the number of test cases that will be run by this test.
-
createResult() protected
Creates a default TestResult object.
-
createTest() public static
-
getGroupDetails() public
-
getGroups() public
Returns the test groups of the suite.
-
getIterator() public
Returns an iterator for this test suite.
-
getName() public
Returns the name of the suite.
-
incompleteTest() protected static
-
injectFilter() public
-
isTestMethod() public static
-
markTestSuiteSkipped() public
Mark the test suite as skipped.
-
run() public
Runs the tests and collects their result in a TestResult.
-
runTest() public deprecated
Runs a test.
-
setBackupGlobals() public
-
setBackupStaticAttributes() public
-
setBeStrictAboutChangesToGlobalState() public
-
setGroupDetails() public
Set tests groups of the test case
-
setName() public
Sets the name of the suite.
-
setRunTestInSeparateProcess() public
-
setTests() public
Set tests of the test suite
-
setUp() protected
Template Method that is called before the tests of this test suite are run.
-
skipTest() protected static
-
tearDown() protected
Template Method that is called after the tests of this test suite have finished running.
-
testAt() public
Returns the test at the given index.
-
tests() public
Returns the tests as an enumeration.
-
toString() public
Returns a string representation of the test suite.
-
warning() protected static
Method Detail
__construct() ¶ public
__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 optional -
string$name optional
Throws
ExceptionaddTest() ¶ public
addTest(Test $test, array $groups = [])
Adds a test to the suite.
Parameters
-
Test$test -
array$groups optional
addTestDirectory() ¶ public
addTestDirectory(string $directory = '.'): void
Adds all the files in a directory to the test suite. Does not recursive through directories.
Parameters
-
string$directory optional The directory to add tests from.
Returns
voidaddTestDirectoryRecursive() ¶ public
addTestDirectoryRecursive(string $directory = '.'): void
Recursively adds all the files in a directory to the test suite.
Parameters
-
string$directory optional The directory subtree to add tests from.
Returns
voidaddTestFile() ¶ public
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
Throws
ExceptionaddTestFiles() ¶ public
addTestFiles(array|Iterator $filenames)
Wrapper for addTestFile() that adds multiple test files.
Parameters
-
array|Iterator$filenames
Throws
ExceptionaddTestMethod() ¶ protected
addTestMethod(ReflectionClass $class, ReflectionMethod $method)
Parameters
-
ReflectionClass$class -
ReflectionMethod$method
addTestSuite() ¶ public
addTestSuite(mixed $testClass)
Adds the tests from the given class to the suite.
Parameters
-
mixed$testClass
Throws
Exceptioncount() ¶ public
count(bool $preferCache = false): int
Counts the number of test cases that will be run by this test.
Parameters
-
bool$preferCache optional Indicates if cache is preferred.
Returns
intcreateResult() ¶ protected
createResult(): TestResult
Creates a default TestResult object.
Returns
TestResultcreateTest() ¶ public static
createTest(ReflectionClass $theClass, string $name): Test
Parameters
-
ReflectionClass$theClass -
string$name
Returns
TestThrows
ExceptiongetIterator() ¶ public
getIterator(): TestSuiteIterator
Returns an iterator for this test suite.
Returns
TestSuiteIteratorincompleteTest() ¶ protected static
incompleteTest(string $class, string $methodName, string $message): IncompleteTestCase
Parameters
-
string$class -
string$methodName -
string$message
Returns
IncompleteTestCaseisTestMethod() ¶ public static
isTestMethod(ReflectionMethod $method): bool
Parameters
-
ReflectionMethod$method
Returns
boolmarkTestSuiteSkipped() ¶ public
markTestSuiteSkipped(string $message = '')
Mark the test suite as skipped.
Parameters
-
string$message optional
Throws
SkippedTestSuiteErrorrun() ¶ public
run(TestResult $result = null): TestResult
Runs the tests and collects their result in a TestResult.
Parameters
-
TestResult$result optional
Returns
TestResultrunTest() ¶ public
runTest(Test $test, TestResult $result)
Runs a test.
Parameters
-
Test$test -
TestResult$result
setBackupStaticAttributes() ¶ public
setBackupStaticAttributes(bool $backupStaticAttributes)
Parameters
-
bool$backupStaticAttributes
setBeStrictAboutChangesToGlobalState() ¶ public
setBeStrictAboutChangesToGlobalState(bool $beStrictAboutChangesToGlobalState)
Parameters
-
bool$beStrictAboutChangesToGlobalState
setGroupDetails() ¶ public
setGroupDetails(array $groups)
Set tests groups of the test case
Parameters
-
array$groups
setRunTestInSeparateProcess() ¶ public
setRunTestInSeparateProcess(bool $runTestInSeparateProcess)
Parameters
-
bool$runTestInSeparateProcess
Throws
ExceptionsetUp() ¶ protected
setUp()
Template Method that is called before the tests of this test suite are run.
skipTest() ¶ protected static
skipTest(string $class, string $methodName, string $message): SkippedTestCase
Parameters
-
string$class -
string$methodName -
string$message
Returns
SkippedTestCasetearDown() ¶ protected
tearDown()
Template Method that is called after the tests of this test suite have finished running.
testAt() ¶ public
testAt(mixed $index): Test|false
Returns the test at the given index.
Parameters
-
$index
Returns
Test|falsetoString() ¶ public
toString(): string
Returns a string representation of the test suite.
Returns
stringwarning() ¶ protected static
warning(string $message): WarningTestCase
Parameters
-
string$message
Returns
WarningTestCase