PHPUnit_Framework_TestCase

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: <code> <?php class MathTest extends PHPUnit_Framework_TestCase { public $value1; public $value2; protected function setUp() { $this->value1 = 2; $this->value2 = 3; } } ?> </code> For each test implement a method which interacts with the fixture. Verify the expected results with assertions specified by calling assert with a boolean. <code> <?php public function testPass() { $this->assertTrue($this->value1 + $this->value2 == 5); } ?> </code>
extends PHPUnit_Framework_Assert implements Countable , PHPUnit_Framework_SelfDescribing , PHPUnit_Framework_Test

Known subclasses

Omeka\Test\AbstractHttpControllerTestCase, Omeka\Test\DbTestCase, Omeka\Test\TestCase, PHPUnit\Framework\TestCase, Zend\Test\PHPUnit\Controller\AbstractControllerTestCase, Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase
Abstract
Open source code
Methods Summary
public
# __construct( string $name = NULL, array $data = array ( ), string $dataName = '' )
Constructs a test case with the given name.
public
# toString( )
Returns a string representation of the test case.

Implementation of

public
# count( )
Counts the number of test cases executed by run(TestResult result).

Implementation of

public
# getAnnotations( )
Returns the annotations for this test.
public
# getName( bool $withDataSet = true )
Gets the name of a TestCase.
public
# getSize( )
Returns the size of the test.
public
public
public
# expectOutputRegex( string $expectedRegex )
public
# expectOutputString( string $expectedString )
public
public
public
public
# setExpectedException( mixed $exceptionName , string $exceptionMessage = '', int $exceptionCode = NULL )
public
# setExpectedExceptionRegExp( mixed $exceptionName , string $exceptionMessageRegExp = '', int $exceptionCode = NULL )
protected
public
# setUseErrorHandler( bool $useErrorHandler )
protected
protected
public
# getStatus( )
Returns the status of this test.
public
# getStatusMessage( )
Returns the status message of this test.
public
# hasFailed( )
Returns whether or not this test has failed.
public
# 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.

Implementation of

public
# runBare( )
Runs the bare test sequence.
protected
# runTest( )
Override to run the test and assert its state.
protected
# verifyMockObjects( )
Verifies the mock object expectations.
public
# setName( string $name )
Sets the name of a TestCase.
public
# setDependencies( array $dependencies )
Sets the dependencies of a TestCase.
public
# hasDependencies( )
Returns true if the tests has dependencies
public
# setDependencyInput( array $dependencyInput )
Sets
public
# setDisallowChangesToGlobalState( bool $disallowChangesToGlobalState )
public
# setBackupGlobals( bool $backupGlobals )
Calling this method in setUp() has no effect!
public
# setBackupStaticAttributes( bool $backupStaticAttributes )
Calling this method in setUp() has no effect!
public
# setRunTestInSeparateProcess( bool $runTestInSeparateProcess )
public
# setPreserveGlobalState( bool $preserveGlobalState )
public
# setInIsolation( bool $inIsolation )
public
public
public
# setResult( mixed $result )
public
# setOutputCallback( callable $callback )
public
public
# setTestResultObject( PHPUnit_Framework_TestResult $result )
protected
# iniSet( string $varName , string $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.
protected
# setLocale( )
This method is a wrapper for the setlocale() function that automatically resets the locale to its original value after the test is run.
public
# getMock( string $originalClassName , array|null $methods = array ( ), array $arguments = array ( ), string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = false, bool $callOriginalMethods = false, object $proxyTarget = NULL )
Returns a mock object for the specified class.
public
# getMockBuilder( string $className )
Returns a builder object to create mock objects using a fluent interface.
protected
# getMockClass( string $originalClassName , array $methods = array ( ), array $arguments = array ( ), string $mockClassName = '', bool $callOriginalConstructor = false, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = false )
Mocks the specified class and returns the name of the mocked class.
public
# getMockForAbstractClass( string $originalClassName , array $arguments = array ( ), string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = array ( ), bool $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).
protected
# getMockFromWsdl( string $wsdlFile , string $originalClassName = '', string $mockClassName = '', array $methods = array ( ), bool $callOriginalConstructor = true, array $options = array ( ) )
Returns a mock object based on the given WSDL file.
public
# getMockForTrait( string $traitName , array $arguments = array ( ), string $mockClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, array $mockedMethods = array ( ), bool $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 `$mockedMethods` parameter.
protected
# getObjectForTrait( string $traitName , array $arguments = array ( ), string $traitClassName = '', bool $callOriginalConstructor = true, bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = false )
Returns an object for the specified trait.
protected
# prophesize( string|null $classOrInterface = NULL )
public
# addToAssertionCount( int $count )
Adds a value to the assertion counter.
public
# getNumAssertions( )
Returns the number of assertions performed by this test.
public static
# any( )
Returns a matcher that matches when the method is executed zero or more times.
public static
# never( )
Returns a matcher that matches when the method is never executed.
public static
# atLeast( int $requiredInvocations )
Returns a matcher that matches when the method is executed at least N times.
public static
# atLeastOnce( )
Returns a matcher that matches when the method is executed at least once.
public static
# once( )
Returns a matcher that matches when the method is executed exactly once.
public static
# exactly( int $count )
Returns a matcher that matches when the method is executed exactly $count times.
public static
# atMost( int $allowedInvocations )
Returns a matcher that matches when the method is executed at most N times.
public static
# at( int $index )
Returns a matcher that matches when the method is executed at the given index.
public static
# returnValue( mixed $value )
public static
# returnValueMap( array $valueMap )
public static
# returnArgument( int $argumentIndex )
public static
# returnCallback( mixed $callback )
public static
# returnSelf( )
Returns the current object. This method is useful when mocking a fluent interface.
public static
# throwException( Exception $exception )
public static
protected
# getDataSetAsString( bool $includeData = true )
Gets the data set description of a TestCase.
protected
# createResult( )
Creates a default TestResult object.
protected
public static
# setUpBeforeClass( )
This method is called before the first test of this test class is run.
protected
# setUp( )
Sets up the fixture, for example, open a network connection. This method is called before a test is executed.
protected
# 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.
protected
# 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
# tearDown( )
Tears down the fixture, for example, close a network connection. This method is called after a test is executed.
public static
# tearDownAfterClass( )
This method is called after the last test of this test class is run.
protected
# onNotSuccessfulTest( Exception $e )
This method is called when a test method did not execute successfully.
protected
# prepareTemplate( Text_Template $template )
Performs custom preparations on the process isolation template.
protected
# getMockObjectGenerator( )
Get the mock object generator, creating it if it doesn't exist.
Methods inherited from PHPUnit_Framework_Assert
assertArrayHasKey(), assertArraySubset(), assertArrayNotHasKey(), assertContains(), assertAttributeContains(), assertNotContains(), assertAttributeNotContains(), assertContainsOnly(), assertContainsOnlyInstancesOf(), assertAttributeContainsOnly(), assertNotContainsOnly(), assertAttributeNotContainsOnly(), assertCount(), assertAttributeCount(), assertNotCount(), assertAttributeNotCount(), assertEquals(), assertAttributeEquals(), assertNotEquals(), assertAttributeNotEquals(), assertEmpty(), assertAttributeEmpty(), assertNotEmpty(), assertAttributeNotEmpty(), assertGreaterThan(), assertAttributeGreaterThan(), assertGreaterThanOrEqual(), assertAttributeGreaterThanOrEqual(), assertLessThan(), assertAttributeLessThan(), assertLessThanOrEqual(), assertAttributeLessThanOrEqual(), assertFileEquals(), assertFileNotEquals(), assertStringEqualsFile(), assertStringNotEqualsFile(), assertFileExists(), assertFileNotExists(), assertTrue(), assertNotTrue(), assertFalse(), assertNotFalse(), assertNotNull(), assertNull(), assertClassHasAttribute(), assertClassNotHasAttribute(), assertClassHasStaticAttribute(), assertClassNotHasStaticAttribute(), assertObjectHasAttribute(), assertObjectNotHasAttribute(), assertSame(), assertAttributeSame(), assertNotSame(), assertAttributeNotSame(), assertInstanceOf(), assertAttributeInstanceOf(), assertNotInstanceOf(), assertAttributeNotInstanceOf(), assertInternalType(), assertAttributeInternalType(), assertNotInternalType(), assertAttributeNotInternalType(), assertRegExp(), assertNotRegExp(), assertSameSize(), assertNotSameSize(), assertStringMatchesFormat(), assertStringNotMatchesFormat(), assertStringMatchesFormatFile(), assertStringNotMatchesFormatFile(), assertStringStartsWith(), assertStringStartsNotWith(), assertStringEndsWith(), assertStringEndsNotWith(), assertXmlFileEqualsXmlFile(), assertXmlFileNotEqualsXmlFile(), assertXmlStringEqualsXmlFile(), assertXmlStringNotEqualsXmlFile(), assertXmlStringEqualsXmlString(), assertXmlStringNotEqualsXmlString(), assertEqualXMLStructure(), assertSelectCount(), assertSelectRegExp(), assertSelectEquals(), assertTag(), assertNotTag(), assertThat(), assertJson(), assertJsonStringEqualsJsonString(), assertJsonStringNotEqualsJsonString(), assertJsonStringEqualsJsonFile(), assertJsonStringNotEqualsJsonFile(), assertJsonFileNotEqualsJsonFile(), assertJsonFileEqualsJsonFile(), logicalAnd(), logicalOr(), logicalNot(), logicalXor(), anything(), isTrue(), callback(), isFalse(), isJson(), isNull(), attribute(), contains(), containsOnly(), containsOnlyInstancesOf(), arrayHasKey(), equalTo(), attributeEqualTo(), isEmpty(), fileExists(), greaterThan(), greaterThanOrEqual(), classHasAttribute(), classHasStaticAttribute(), objectHasAttribute(), identicalTo(), isInstanceOf(), isType(), lessThan(), lessThanOrEqual(), matchesRegularExpression(), matches(), stringStartsWith(), stringContains(), stringEndsWith(), countOf(), fail(), readAttribute(), getStaticAttribute(), getObjectAttribute(), markTestIncomplete(), markTestSkipped(), getCount(), resetCount()
Properties Summary
protected bool $backupGlobals
Enable or disable the backup and restoration of the $GLOBALS array. Overwrite this attribute in a child class of TestCase. Setting this attribute in setUp() has no effect!
# NULL
protected array $backupGlobalsBlacklist
# array ( )
protected bool $backupStaticAttributes
Enable or disable the backup and restoration of static attributes. Overwrite this attribute in a child class of TestCase. Setting this attribute in setUp() has no effect!
# NULL
protected array $backupStaticAttributesBlacklist
# array ( )
protected bool $runTestInSeparateProcess
Whether or not this test is to be run in a separate PHP process.
# NULL
protected bool $preserveGlobalState
Whether or not this test should preserve the global state when running in a separate PHP process.
# true