PHPUnit Manual
Edition for PHPUnit 13.3. Updated on Aug 07, 2026.
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
- 7. Code Coverage
- 8. TestDox
- 9. Risky Tests
- 10. Flaky Tests
- 11. Error Handling
- Limiting issues to “your code”
- Failing on deprecations based on how they are triggered
- Ignoring issue suppression
- Ignoring previously reported issues
- Expecting Deprecations (
E_USER_DEPRECATED) - Wrappers for trigger_error()
- Custom Issue Trigger Resolvers
- Custom Deprecation Filters
- Errors (
E_USER_ERROR) - Issues triggered outside of tests
- Error handlers registered by tests
- Disabling PHPUnit’s error handler
- 12. Extending PHPUnit
Appendix
- 1. Assertions
- Static vs. Non-Static Usage of Assertion Methods
- Boolean
- Identity
- Equality
assertEquals()assertEqualsCanonicalizing()assertEqualsIgnoringCase()assertEqualsWithDelta()assertObjectEquals()assertFileEquals()assertFileEqualsFileIgnoringWhitespace()assertArraysAreEqual()assertArraysAreEqualIgnoringOrder()assertArraysHaveEqualValues()assertArraysHaveEqualValuesIgnoringOrder()assertArrayIsEqualToArrayOnlyConsideringListOfKeys()assertArrayIsEqualToArrayIgnoringListOfKeys()
- Iterable
assertArrayHasKey()assertContains()assertContainsOnly()assertContainsOnlyArray()assertContainsOnlyBool()assertContainsOnlyCallable()assertContainsOnlyFloat()assertContainsOnlyInt()assertContainsOnlyIterable()assertContainsOnlyNull()assertContainsOnlyNumeric()assertContainsOnlyObject()assertContainsOnlyResource()assertContainsOnlyClosedResource()assertContainsOnlyScalar()assertContainsOnlyString()assertContainsOnlyInstancesOf()
- Objects
- Cardinality
- Types
- Strings
assertStringStartsWith()assertStringEndsWith()assertStringContainsString()assertStringContainsStringIgnoringCase()assertStringEqualsStringIgnoringLineEndings()assertStringEqualsStringIgnoringWhitespace()assertMatchesRegularExpression()assertStringMatchesFormat()assertStringMatchesFormatFile()assertFileMatchesFormat()assertFileMatchesFormatFile()assertStringEqualsFile()assertStringEqualsFileIgnoringWhitespace()
- JSON
- XML
- Filesystem
- Math
- Constraints
- 2. Attributes
TestAllowMockObjectsWithoutExpectationsDisableReturnValueGenerationForTestDoublesDoesNotPerformAssertionsIgnoreDeprecationsWithoutErrorHandlerIgnorePhpunitWarnings- Code Coverage
CoversClassCoversClassesThatImplementInterfaceCoversClassesThatExtendClassCoversTraitCoversMethodCoversFunctionCoversNamespaceCoversFileCoversDirectoryCoversDirectoryRecursivelyCoversNothingUsesClassUsesClassesThatImplementInterfaceUsesClassesThatExtendClassUsesTraitUsesMethodUsesFunctionUsesNamespaceUsesFileUsesDirectoryUsesDirectoryRecursively
- Data Provider
- Test Dependencies
- TestDox
- Test Groups
- Template Methods
- Test Isolation
- Flaky Tests
- Skipping Tests
- 3. Configuration
- 4. CLI Options
- 5. XML Configuration File
- The
<phpunit>Element- The
backupGlobalsAttribute - The
backupStaticPropertiesAttribute - The
bootstrapAttribute - The
cacheDirectoryAttribute - The
recordTestRunHistoryAttribute - The
colorsAttribute - The
columnsAttribute - The
controlGarbageCollectorAttribute - The
numberOfTestsBeforeGarbageCollectionAttribute - The
requireCoverageMetadataAttribute - The
requireSealedMockObjectsAttribute - The
processIsolationAttribute - The
stopOnDefectAttribute - The
stopOnErrorAttribute - The
stopOnFailureAttribute - The
stopOnWarningAttribute - The
stopOnRiskyAttribute - The
stopOnDeprecationAttribute - The
stopOnNoticeAttribute - The
stopOnSkippedAttribute - The
stopOnIncompleteAttribute - The
failOnAllIssuesAttribute - The
failOnEmptyTestSuiteAttribute - The
failOnWarningAttribute - The
failOnRiskyAttribute - The
failOnDeprecationAttribute - The
failOnSelfDeprecationAttribute - The
failOnDirectDeprecationAttribute - The
failOnIndirectDeprecationAttribute - The
failOnPhpunitDeprecationAttribute - The
failOnPhpunitNoticeAttribute - The
failOnPhpunitWarningAttribute - The
failOnNoticeAttribute - The
failOnSkippedAttribute - The
failOnIncompleteAttribute - The
beStrictAboutChangesToGlobalStateAttribute - The
beStrictAboutOutputDuringTestsAttribute - The
beStrictAboutTestsThatDoNotTestAnythingAttribute - The
beStrictAboutCoverageMetadataAttribute - The
requireCoverageContributionAttribute - The
enforceTimeLimitAttribute - The
defaultTimeLimitAttribute - The
diffContextAttribute - The
timeoutForSmallTestsAttribute - The
timeoutForMediumTestsAttribute - The
timeoutForLargeTestsAttribute - The
defaultTestSuiteAttribute - The
stderrAttribute - The
reverseDefectListAttribute - The
registerMockObjectsFromTestArgumentsRecursivelyAttribute - The
extensionsDirectoryAttribute - The
executionOrderAttribute - The
resolveDependenciesAttribute - The
testdoxAttribute - The
testdoxSummaryAttribute - The
displayDetailsOnAllIssuesAttribute - The
displayDetailsOnIncompleteTestsAttribute - The
displayDetailsOnSkippedTestsAttribute - The
displayDetailsOnTestsThatTriggerDeprecationsAttribute - The
displayDetailsOnPhpunitDeprecationsAttribute - The
displayDetailsOnPhpunitNoticesAttribute - The
displayDetailsOnTestsThatTriggerErrorsAttribute - The
displayDetailsOnTestsThatTriggerNoticesAttribute - The
displayDetailsOnTestsThatTriggerWarningsAttribute - The
shortenArraysForExportThresholdAttribute - The
warnWhenPhpIsNotConfiguredForDevelopmentAttribute
- The
- The
<testsuites>Element - The
<source>Element- The
<include>Element - The
<exclude>Element - The
<directory>Element - The
<file>Element - The
<deprecationTrigger>Element - The
<issueTriggerResolvers>Element - The
<deprecationFilters>Element - The
<identifyIssueTrigger>Attribute - The
<ignoreSelfDeprecations>Attribute - The
<ignoreDirectDeprecations>Attribute - The
<ignoreIndirectDeprecations>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. Events
- 7. PHPT Tests
- 8. Copyright