- \PHPUnit_Framework_Assert- \PHPUnit_Framework_TestCase
 
abstract class (none) \ PHPUnit_Framework_TestCase
- All implemented interfaces:
- Countable, PHPUnit_Framework_Test, PHPUnit_Framework_SelfDescribing
- All known direct subclasses:
- PHPUnit_Framework_IncompleteTestCase, PHPUnit_Framework_SkippedTestCase, PHPUnit_Framework_Warning
A TestCase defines the fixture to run multiple tests.
To define a TestCase
1) Implement a subclass of PHPUnit_Framework_TestCase. 2) Define instance variables that store the state of the fixture. 3) Initialize the fixture state by overriding setUp(). 4) Clean-up after a test by overriding tearDown().
Each test runs in its own fixture so there can be no side effects among test runs.
Here is an example:
protected function setUp() { $this->value1 = 2; $this->value2 = 3; } } ?>  
For each test implement a method which interacts with the fixture. Verify the expected results with assertions specified by calling assert with a boolean.
 assertTrue($this->value1 + $this->value2 == 5); } ?> 
Method Summary
Inherited Method Summary
public function __construct($name = null, array $data = array(), $dataName = "")
Constructs a test case with the given name.
- Parameters:
string- $dataNamearray- $data- Defaults:
name=nulldata= array()dataName=""
public function addToAssertionCount($count)
Adds a value to the assertion counter.
- Parameters:
integer- $count
public static function any()
Returns a matcher that matches when the method it is evaluated for is executed zero or more times.
- Returns:
- PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount
protected function assertPostConditions()
Performs assertions shared by all tests of a test case.
This method is called before the execution of a test ends and before tearDown() is called.
protected function assertPreConditions()
Performs assertions shared by all tests of a test case.
This method is called before the execution of a test starts and after setUp() is called.
public static function at($index)
Returns a matcher that matches when the method it is evaluated for is invoked at the given $index.
- Parameters:
integer- $index- Returns:
- PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex
public static function atLeast($requiredInvocations)
Returns a matcher that matches when the method it is evaluated for is executed at least N times.
- Parameters:
integer- $requiredInvocations- Returns:
- PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount
public static function atLeastOnce()
Returns a matcher that matches when the method it is evaluated for is executed at least once.
- Returns:
- PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce
public static function atMost($allowedInvocations)
Returns a matcher that matches when the method it is evaluated for is executed at most N times.
- Parameters:
integer- $allowedInvocations- Returns:
- PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount
protected function checkRequirements()
private function compareGlobalStateSnapshotPart(array $before, array $after, $header)
- Parameters:
array- $afterstring- $header- Throws:
- PHPUnit_Framework_RiskyTestError
private function compareGlobalStateSnapshots(Snapshot $before, Snapshot $after)
- Parameters:
Snapshot- $after- Throws:
- PHPUnit_Framework_RiskyTestError
public function count()
Counts the number of test cases executed by run(TestResult result).
- Returns:
- integer
private function createGlobalStateSnapshot($backupGlobals)
- Parameters:
boolean- $backupGlobals- Returns:
- Snapshot
protected function createResult()
Creates a default TestResult object.
- Returns:
- PHPUnit_Framework_TestResult
public static function exactly($count)
Returns a matcher that matches when the method it is evaluated for is executed exactly $count times.
- Parameters:
integer- $count- Returns:
- PHPUnit_Framework_MockObject_Matcher_InvokedCount
public function expectOutputRegex($expectedRegex)
- Parameters:
string- $expectedRegex- Throws:
- PHPUnit_Framework_Exception
public function expectOutputString($expectedString)
- Parameters:
string- $expectedString
public function getActualOutput()
- Returns:
- string
public function getAnnotations()
Returns the annotations for this test.
- Returns:
- array
protected function getDataSetAsString($includeData = true)
Gets the data set description of a TestCase.
- Parameters:
boolean- $includeData- Defaults:
includeData=true- Returns:
- string
public function getExpectedException()
- Returns:
- string
public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = "", $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false)
Returns a mock object for the specified class.
- Parameters:
string- $mockClassName Class name for the generated test double class.array|null- $methods When provided, only methods whose names are in the array are replaced with a configurable test double. The behavior of the other methods is not changed. Providing null means that no methods will be replaced.array- $arguments Parameters to pass to the original class' constructor.boolean- $callOriginalMethods- Defaults:
methods= array()arguments= array()mockClassName=""callOriginalConstructor=truecallOriginalClone=truecallAutoload=truecloneArguments=falsecallOriginalMethods=false- Returns:
- PHPUnit_Framework_MockObject_MockObject
- Throws:
- PHPUnit_Framework_Exception
public function getMockBuilder($className)
Returns a builder object to create mock objects using a fluent interface.
- Parameters:
string- $className- Returns:
- PHPUnit_Framework_MockObject_MockBuilder
protected function getMockClass($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = "", $callOriginalConstructor = false, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false)
Mocks the specified class and returns the name of the mocked class.
- Parameters:
string- $mockClassNamearray- $argumentsboolean- $cloneArguments- Defaults:
methods= array()arguments= array()mockClassName=""callOriginalConstructor=falsecallOriginalClone=truecallAutoload=truecloneArguments=false- Returns:
- string
- Throws:
- PHPUnit_Framework_Exception
public function getMockForAbstractClass($originalClassName, array $arguments = array(), $mockClassName = "", $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = array(), $cloneArguments = false)
Returns a mock object for the specified abstract class with all abstract methods of the class mocked. Concrete methods are not mocked by default. To mock concrete methods, use the 7th parameter ($mockedMethods).
- Parameters:
string- $mockClassNamearray- $mockedMethodsboolean- $cloneArguments- Defaults:
arguments= array()mockClassName=""callOriginalConstructor=truecallOriginalClone=truecallAutoload=truemockedMethods= array()cloneArguments=false- Returns:
- PHPUnit_Framework_MockObject_MockObject
- Throws:
- PHPUnit_Framework_Exception
public function getMockForTrait($traitName, array $arguments = array(), $mockClassName = "", $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = array(), $cloneArguments = false)
Returns a mock object for the specified trait with all abstract methods of the trait mocked. Concrete methods to mock can be specified with the
$mockedMethodsparameter.
- Parameters:
string- $mockClassNamearray- $mockedMethodsboolean- $cloneArguments- Defaults:
arguments= array()mockClassName=""callOriginalConstructor=truecallOriginalClone=truecallAutoload=truemockedMethods= array()cloneArguments=false- Returns:
- PHPUnit_Framework_MockObject_MockObject
- Throws:
- PHPUnit_Framework_Exception
protected function getMockFromWsdl($wsdlFile, $originalClassName = "", $mockClassName = "", array $methods = array(), $callOriginalConstructor = true, array $options = array())
Returns a mock object based on the given WSDL file.
- Parameters:
string- $mockClassNamearray- $options An array of options passed to SOAPClient::_constructboolean- $callOriginalConstructor- Defaults:
originalClassName=""mockClassName=""methods= array()callOriginalConstructor=trueoptions= array()- Returns:
- PHPUnit_Framework_MockObject_MockObject
protected function getMockObjectGenerator()
Get the mock object generator, creating it if it doesn't exist.
- Returns:
- PHPUnit_Framework_MockObject_Generator
public function getName($withDataSet = true)
Gets the name of a TestCase.
- Parameters:
boolean- $withDataSet- Defaults:
withDataSet=true- Returns:
- string
public function getNumAssertions()
Returns the number of assertions performed by this test.
- Returns:
- integer
protected function getObjectForTrait($traitName, array $arguments = array(), $traitClassName = "", $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false)
Returns an object for the specified trait.
- Parameters:
string- $traitClassNamearray- $argumentsboolean- $cloneArguments- Defaults:
arguments= array()traitClassName=""callOriginalConstructor=truecallOriginalClone=truecallAutoload=truecloneArguments=false- Returns:
- object
- Throws:
- PHPUnit_Framework_Exception
private function getProphet()
- Returns:
- Prophecy\Prophet
public function getResult()
- Returns:
- mixed
public function getSize()
Returns the size of the test.
- Returns:
- integer
public function getStatus()
Returns the status of this test.
- Returns:
- integer
public function getStatusMessage()
Returns the status message of this test.
- Returns:
- string
public function getTestResultObject()
- Returns:
- PHPUnit_Framework_TestResult
protected function handleDependencies()
public function hasDependencies()
Returns true if the tests has dependencies
- Returns:
- boolean
public function hasExpectationOnOutput()
- Returns:
- bool
public function hasFailed()
Returns whether or not this test has failed.
- Returns:
- boolean
public function hasOutput()
- Returns:
- boolean
public function hasPerformedExpectationsOnOutput()
- Returns:
- bool
protected function iniSet($varName, $newValue)
This method is a wrapper for the ini_set() function that automatically resets the modified php.ini setting to its original value after the test is run.
- Parameters:
string- $newValue- Throws:
- PHPUnit_Framework_Exception
public function isInIsolation()
- Returns:
- boolean
public static function never()
Returns a matcher that matches when the method it is evaluated for is never executed.
- Returns:
- PHPUnit_Framework_MockObject_Matcher_InvokedCount
public static function onConsecutiveCalls()
- Parameters:
mixed- $value, ...- Returns:
- PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls
protected function onNotSuccessfulTest(Exception $e)
This method is called when a test method did not execute successfully.
- Parameters:
Exception- $e- Throws:
- Exception
public static function once()
Returns a matcher that matches when the method it is evaluated for is executed exactly once.
- Returns:
- PHPUnit_Framework_MockObject_Matcher_InvokedCount
protected function prepareTemplate(Text_Template $template)
Performs custom preparations on the process isolation template.
- Parameters:
Text_Template- $template
protected function prophesize($classOrInterface = null)
- Parameters:
string|null- $classOrInterface- Defaults:
classOrInterface=null- Returns:
- \Prophecy\Prophecy\ObjectProphecy
- Throws:
- \LogicException
private function restoreGlobalState()
public static function returnArgument($argumentIndex)
- Parameters:
integer- $argumentIndex- Returns:
- PHPUnit_Framework_MockObject_Stub_ReturnArgument
public static function returnCallback($callback)
- Parameters:
mixed- $callback- Returns:
- PHPUnit_Framework_MockObject_Stub_ReturnCallback
public static function returnSelf()
Returns the current object.
This method is useful when mocking a fluent interface.
- Returns:
- PHPUnit_Framework_MockObject_Stub_ReturnSelf
public static function returnValue($value)
- Parameters:
mixed- $value- Returns:
- PHPUnit_Framework_MockObject_Stub_Return
public static function returnValueMap(array $valueMap)
- Parameters:
array- $valueMap- Returns:
- PHPUnit_Framework_MockObject_Stub_ReturnValueMap
public function run(PHPUnit_Framework_TestResult $result = null)
Runs the test case and collects the results in a TestResult object. If no TestResult object is passed a new one will be created.
- Parameters:
PHPUnit_Framework_TestResult- $result- Defaults:
result=null- Returns:
- PHPUnit_Framework_TestResult
- Throws:
- PHPUnit_Framework_Exception
public function runBare()
Runs the bare test sequence.
protected function runTest()
Override to run the test and assert its state.
- Returns:
- mixed
- Throws:
- Exception|PHPUnit_Framework_Exception
PHPUnit_Framework_Exception
public function setBackupGlobals($backupGlobals)
Calling this method in setUp() has no effect!
- Parameters:
boolean- $backupGlobals
public function setBackupStaticAttributes($backupStaticAttributes)
Calling this method in setUp() has no effect!
- Parameters:
boolean- $backupStaticAttributes
public function setDependencies(array $dependencies)
Sets the dependencies of a TestCase.
- Parameters:
array- $dependencies
public function setDependencyInput(array $dependencyInput)
Sets
- Parameters:
array- $dependencyInput
public function setDisallowChangesToGlobalState($disallowChangesToGlobalState)
- Parameters:
boolean- $disallowChangesToGlobalState
public function setExpectedException($exceptionName, $exceptionMessage = "", $exceptionCode = null)
- Parameters:
mixed- $exceptionNamestring- $exceptionMessageinteger- $exceptionCode- Defaults:
exceptionMessage=""exceptionCode=null
protected function setExpectedExceptionFromAnnotation()
public function setExpectedExceptionRegExp($exceptionName, $exceptionMessageRegExp = "", $exceptionCode = null)
- Parameters:
mixed- $exceptionNamestring- $exceptionMessageRegExpinteger- $exceptionCode- Defaults:
exceptionMessageRegExp=""exceptionCode=null
public function setInIsolation($inIsolation)
- Parameters:
boolean- $inIsolation- Throws:
- PHPUnit_Framework_Exception
protected function setLocale()
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
- Parameters:
integer- $categorystring- $locale- Throws:
- PHPUnit_Framework_Exception
public function setName($name)
Sets the name of a TestCase.
- Parameters:
string-
public function setOutputCallback($callback)
- Parameters:
callable- $callback- Throws:
- PHPUnit_Framework_Exception
public function setPreserveGlobalState($preserveGlobalState)
- Parameters:
boolean- $preserveGlobalState- Throws:
- PHPUnit_Framework_Exception
public function setResult($result)
- Parameters:
mixed- $result
public function setRunTestInSeparateProcess($runTestInSeparateProcess)
- Parameters:
boolean- $runTestInSeparateProcess- Throws:
- PHPUnit_Framework_Exception
public function setTestResultObject(PHPUnit_Framework_TestResult $result)
- Parameters:
PHPUnit_Framework_TestResult- $result
protected function setUp()
Sets up the fixture, for example, open a network connection. This method is called before a test is executed.
public static function setUpBeforeClass()
This method is called before the first test of this test class is run.
public function setUseErrorHandler($useErrorHandler)
- Parameters:
boolean- $useErrorHandler
protected function setUseErrorHandlerFromAnnotation()
private function snapshotGlobalState()
private function startOutputBuffering()
private function stopOutputBuffering()
protected function tearDown()
Tears down the fixture, for example, close a network connection. This method is called after a test is executed.
public static function tearDownAfterClass()
This method is called after the last test of this test class is run.
public static function throwException(Exception $exception)
- Parameters:
Exception- $exception- Returns:
- PHPUnit_Framework_MockObject_Stub_Exception
public function toString()
Returns a string representation of the test case.
- Returns:
- string
protected function verifyMockObjects()
Verifies the mock object expectations.