PHPUnit Manual
Edition for PHPUnit 11.4. Updated on Nov 28, 2024.
Sebastian Bergmann
This work is licensed under the Creative Commons Attribution 3.0 Unported License.
Contents:
- 1. Installation
- 2. Writing Tests for PHPUnit
- 3. The Command-Line Test Runner
- 4. Organizing Tests
- 5. Fixtures
- 6. Test Doubles
- Test Stubs
- Mock Objects
- MockBuilder API
setMockClassName()
setConstructorArgs()
disableOriginalConstructor()
disableOriginalClone()
enableArgumentCloning()
disableAutoReturnValueGeneration()
disallowMockingUnknownTypes()
disableAutoload()
enableProxyingToOriginalMethods()
onlyMethods()
addMethods()
getMock()
getMockForAbstractClass()
getMockForTrait()
- 7. Code Coverage
- 8. Risky Tests
- 9. Error Handling
- 10. Extending PHPUnit
- 1. Assertions
- Static vs. Non-Static Usage of Assertion Methods
- Boolean
- Identity
- Equality
- Iterable
- Objects
- Cardinality
- Types
- Strings
assertStringStartsWith()
assertStringEndsWith()
assertStringContainsString()
assertStringContainsStringIgnoringCase()
assertStringEqualsStringIgnoringLineEndings()
assertMatchesRegularExpression()
assertStringMatchesFormat()
assertStringMatchesFormatFile()
assertFileMatchesFormat()
assertFileMatchesFormatFile()
assertStringEqualsFile()
- JSON
- XML
- Filesystem
- Math
- Constraints
- 2. Attributes
- 3. Annotations
- @author
- @after
- @afterClass
- @backupGlobals
- @backupStaticAttributes
- @before
- @beforeClass
- @codeCoverageIgnore*
- @covers
- @coversDefaultClass
- @coversNothing
- @dataProvider
- @depends
- @doesNotPerformAssertions
- @group
- @large
- @medium
- @preserveGlobalState
- @requires
- @runTestsInSeparateProcesses
- @runInSeparateProcess
- @small
- @test
- @testdox
- @testWith
- @ticket
- @uses
- 4. Events
- 5. The XML Configuration File
- The
<phpunit>
Element- The
backupGlobals
Attribute - The
backupStaticProperties
Attribute - The
bootstrap
Attribute - The
cacheDirectory
Attribute - The
cacheResult
Attribute - The
colors
Attribute - The
columns
Attribute - The
controlGarbageCollector
Attribute - The
numberOfTestsBeforeGarbageCollection
Attribute - The
requireCoverageMetadata
Attribute - The
processIsolation
Attribute - The
stopOnDefect
Attribute - The
stopOnError
Attribute - The
stopOnFailure
Attribute - The
stopOnWarning
Attribute - The
stopOnRisky
Attribute - The
stopOnDeprecation
Attribute - The
stopOnNotice
Attribute - The
stopOnSkipped
Attribute - The
stopOnIncomplete
Attribute - The
failOnEmptyTestSuite
Attribute - The
failOnWarning
Attribute - The
failOnRisky
Attribute - The
failOnDeprecation
Attribute - The
failOnPhpunitDeprecation
Attribute - The
failOnNotice
Attribute - The
failOnSkipped
Attribute - The
failOnIncomplete
Attribute - The
beStrictAboutChangesToGlobalState
Attribute - The
beStrictAboutOutputDuringTests
Attribute - The
beStrictAboutTestsThatDoNotTestAnything
Attribute - The
beStrictAboutCoverageMetadata
Attribute - The
enforceTimeLimit
Attribute - The
defaultTimeLimit
Attribute - The
timeoutForSmallTests
Attribute - The
timeoutForMediumTests
Attribute - The
timeoutForLargeTests
Attribute - The
defaultTestSuite
Attribute - The
stderr
Attribute - The
reverseDefectList
Attribute - The
registerMockObjectsFromTestArgumentsRecursively
Attribute - The
extensionsDirectory
Attribute - The
executionOrder
Attribute - The
resolveDependencies
Attribute - The
testdox
Attribute - The
testdoxSummary
Attribute - The
displayDetailsOnIncompleteTests
Attribute - The
displayDetailsOnSkippedTests
Attribute - The
displayDetailsOnTestsThatTriggerDeprecations
Attribute - The
displayDetailsOnPhpunitDeprecations
Attribute - The
displayDetailsOnTestsThatTriggerErrors
Attribute - The
displayDetailsOnTestsThatTriggerNotices
Attribute - The
displayDetailsOnTestsThatTriggerWarnings
Attribute - The
shortenArraysForExportThreshold
Attribute
- The
- The
<testsuites>
Element - The
<source>
Element- The
<include>
Element - The
<exclude>
Element - The
<directory>
Element - The
<file>
Element - The
<deprecationTrigger>
Element - The
<ignoreSelfDeprecations>
Attribute - The
<ignoreDirectDeprecations>
Attribute - The
<ignoreIndirectDeprecations>
Attribute - The
<restrictDeprecations>
Attribute - The
<restrictNotices>
Attribute - The
<restrictWarnings>
Attribute - The
<baseline>
Attribute - The
<ignoreSuppressionOfDeprecations>
Attribute - The
<ignoreSuppressionOfPhpDeprecations>
Attribute - The
<ignoreSuppressionOfErrors>
Attribute - The
<ignoreSuppressionOfNotices>
Attribute - The
<ignoreSuppressionOfPhpNotices>
Attribute - The
<ignoreSuppressionOfWarnings>
Attribute - The
<ignoreSuppressionOfPhpWarnings>
Attribute
- The
- The
<coverage>
Element - The
<logging>
Element - The
<groups>
Element - The
<extensions>
Element - The
<php>
Element
- The
- 6. Copyright