PHPUnit
  • 1. Installation
    • PHP on the Command-Line
      • Installing the PHP Command-Line Interpreter
        • Fedora
        • Debian
        • Ubuntu
        • macOS
        • Windows
      • Using the PHP Command-Line Interpreter
      • Configuring PHP for Development
    • Installing PHPUnit
      • PHP Archive (PHAR)
        • Manual Download of PHAR
        • Installing PHPUnit with Phive
        • Updating PHPUnit with Phive
        • What is inside the PHAR?
      • Composer
        • Installing PHPUnit with Composer
        • Updating PHPUnit with Composer
      • PHAR or Composer?
      • Global Installation
      • Web Server
  • 2. Writing Tests for PHPUnit
    • Asserting return values
    • Expecting exceptions
    • Verifying side effects
    • Data Providers
    • Test Dependencies
    • Incomplete Tests
    • Skipping tests
      • Skipping tests using attributes
    • Testing output
    • Testing error log output
  • 3. The Command-Line Test Runner
    • Running tests
      • PHPT tests
    • Selecting tests
      • Filtering by test name
        • Shortcut syntax
        • Regular expression syntax
      • Filtering by test suite
      • Filtering by group
      • Filtering by covered unit
      • Listing tests
    • Outcome and Issues
    • Output
      • Runtime information
      • Progress
      • Test results
        • Failure output
      • Summary
      • Alternative output formats
        • TestDox
        • Debug
        • TeamCity
      • Controlling output
      • Interaction between output options
    • Exit codes
    • Stopping early
    • Logging
    • Test execution order
  • 4. Organizing Tests
    • Composing a Test Suite Using the Filesystem
    • Composing a Test Suite Using XML Configuration
  • 5. Fixtures
    • Template Methods
    • More setUp() than tearDown()
    • Pre-Conditions and Post-Conditions
    • Using Attributes Instead of Template Methods
    • Sharing Fixture
    • Global State
  • 6. Test Doubles
    • Test Stubs
      • What are test stubs?
      • Common use cases
        • Configuring return values
        • Configuring exceptions
      • Reference
        • Creating test stubs
        • Configuring return values
        • Configuring exceptions
      • Return Value Generation
    • Mock Objects
      • What are mock objects?
      • Common use cases
        • Using a mock object for testing direct output
      • Reference
        • Creating mock objects
        • Configuring behavior
        • Configuring expectations
    • Best Practices
  • 7. Code Coverage
    • Software Metrics for Code Coverage
    • Including Files
    • Targeting Units of Code
    • Ignoring Code Blocks
    • Limitations
  • 8. TestDox
    • Default Behaviour
      • Class Names
      • Method Names
      • Data Providers
    • Customizing Test Documentation
      • The TestDox Attribute
        • Using Placeholders with Data Providers
      • The TestDoxFormatter Attribute
      • The TestDoxFormatterExternal Attribute
    • TestDox Output
      • Console Output
      • Plain Text Output
      • HTML Output
      • XML Configuration
  • 9. Risky Tests
    • Useless Tests
    • Unintentionally Covered Code
    • Output During Test Execution
    • Test Execution Timeout
    • Global State Manipulation
    • Test Size Dependencies
  • 10. Error Handling
    • Limiting issues to “your code”
    • Ignoring issue suppression
    • Ignoring previously reported issues
    • Expecting Deprecations (E_USER_DEPRECATED)
    • Disabling PHPUnit’s error handler
  • 11. Extending PHPUnit
    • Enhancing concrete test cases
    • Extracting abstract test cases
    • Extracting traits
    • Implementing custom constraints
    • Implementing custom assertions
    • Implementing custom comparators
    • Extending the Test Runner
      • Implementing an extension
        • Implementing an event subscriber
        • Implementing an event tracer
        • Understanding events
      • Sharing an extension
        • Sharing an extension as a PHAR
        • Sharing an extension as a Composer package
      • Registering an extension
        • Registering an extension from a PHAR
        • Registering an extension from a Composer package
      • Debugging PHPUnit
    • Wrapping the Test Runner

Appendix

  • 1. Assertions
    • Static vs. Non-Static Usage of Assertion Methods
    • Boolean
      • assertTrue()
      • assertFalse()
    • Identity
      • assertSame()
      • assertArrayIsIdenticalToArrayOnlyConsideringListOfKeys()
      • assertArrayIsIdenticalToArrayIgnoringListOfKeys()
    • Equality
      • assertEquals()
      • assertEqualsCanonicalizing()
      • assertEqualsIgnoringCase()
      • assertEqualsWithDelta()
      • assertObjectEquals()
      • assertFileEquals()
      • assertArrayIsEqualToArrayOnlyConsideringListOfKeys()
      • assertArrayIsEqualToArrayIgnoringListOfKeys()
    • Iterable
      • assertArrayHasKey()
      • assertContains()
      • assertContainsOnly()
      • assertContainsOnlyArray()
      • assertContainsOnlyBool()
      • assertContainsOnlyCallable()
      • assertContainsOnlyFloat()
      • assertContainsOnlyInt()
      • assertContainsOnlyIterable()
      • assertContainsOnlyNull()
      • assertContainsOnlyNumeric()
      • assertContainsOnlyObject()
      • assertContainsOnlyResource()
      • assertContainsOnlyClosedResource()
      • assertContainsOnlyScalar()
      • assertContainsOnlyString()
      • assertContainsOnlyInstancesOf()
    • Objects
      • assertObjectHasProperty()
    • Cardinality
      • assertCount()
      • assertSameSize()
      • assertEmpty()
      • assertGreaterThan()
      • assertGreaterThanOrEqual()
      • assertLessThan()
      • assertLessThanOrEqual()
    • Types
      • assertInstanceOf()
      • assertIsArray()
      • assertIsList()
      • assertIsBool()
      • assertIsCallable()
      • assertIsFloat()
      • assertIsInt()
      • assertIsIterable()
      • assertIsNumeric()
      • assertIsObject()
      • assertIsResource()
      • assertIsScalar()
      • assertIsString()
      • assertNull()
    • Strings
      • assertStringStartsWith()
      • assertStringEndsWith()
      • assertStringContainsString()
      • assertStringContainsStringIgnoringCase()
      • assertStringEqualsStringIgnoringLineEndings()
      • assertMatchesRegularExpression()
      • assertStringMatchesFormat()
      • assertStringMatchesFormatFile()
      • assertFileMatchesFormat()
      • assertFileMatchesFormatFile()
      • assertStringEqualsFile()
    • JSON
      • assertJson()
      • assertJsonFileEqualsJsonFile()
      • assertJsonStringEqualsJsonFile()
      • assertJsonStringEqualsJsonString()
    • XML
      • assertXmlFileEqualsXmlFile()
      • assertXmlStringEqualsXmlFile()
      • assertXmlStringEqualsXmlString()
    • Filesystem
      • assertDirectoryExists()
      • assertDirectoryIsReadable()
      • assertDirectoryIsWritable()
      • assertFileExists()
      • assertFileIsReadable()
      • assertFileIsWritable()
      • assertIsReadable()
      • assertIsWritable()
    • Math
      • assertInfinite()
      • assertNan()
    • Constraints
      • assertThat()
  • 2. Attributes
    • Test
    • AllowMockObjectsWithoutExpectations
    • DisableReturnValueGenerationForTestDoubles
    • DoesNotPerformAssertions
    • IgnoreDeprecations
    • WithoutErrorHandler
    • IgnorePhpunitWarnings
    • Code Coverage
      • CoversClass
      • CoversClassesThatImplementInterface
      • CoversClassesThatExtendClass
      • CoversTrait
      • CoversMethod
      • CoversFunction
      • CoversNamespace
      • CoversNothing
      • UsesClass
      • UsesClassesThatImplementInterface
      • UsesClassesThatExtendClass
      • UsesTrait
      • UsesMethod
      • UsesFunction
      • UsesNamespace
    • Data Provider
      • DataProvider
      • DataProviderExternal
      • TestWith
      • TestWithJson
    • Test Dependencies
      • Depends
      • DependsUsingDeepClone
      • DependsUsingShallowClone
      • DependsExternal
      • DependsExternalUsingDeepClone
      • DependsExternalUsingShallowClone
      • DependsOnClass
      • DependsOnClassUsingDeepClone
      • DependsOnClassUsingShallowClone
    • TestDox
      • TestDox
      • TestDoxFormatter
      • TestDoxFormatterExternal
    • Test Groups
      • Group
      • Small
      • Medium
      • Large
      • Ticket
    • Template Methods
      • BeforeClass
      • Before
      • PreCondition
      • PostCondition
      • After
      • AfterClass
    • Test Isolation
      • BackupGlobals
      • ExcludeGlobalVariableFromBackup
      • BackupStaticProperties
      • ExcludeStaticPropertyFromBackup
      • RunInSeparateProcess
      • RunTestsInSeparateProcesses
      • RunClassInSeparateProcess
      • PreserveGlobalState
      • WithEnvironmentVariable
    • Skipping Tests
      • RequiresPhp
      • RequiresPhpExtension
      • RequiresSetting
      • RequiresPhpunit
      • RequiresPhpunitExtension
      • RequiresFunction
      • RequiresMethod
      • RequiresOperatingSystem
      • RequiresOperatingSystemFamily
      • RequiresEnvironmentVariable
  • 3. Configuration
    • Configuration
    • Selection
    • Execution
    • Stopping on Issues
    • Failing on Issues
    • Reporting
    • Logging
    • Code Coverage
    • CLI-only Options
    • XML-only Settings
  • 4. CLI Options
    • Configuration
    • Selection
    • Execution
    • Reporting
    • Logging
    • Code Coverage
    • Miscellaneous
  • 5. 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 failOnAllIssues Attribute
      • The failOnEmptyTestSuite Attribute
      • The failOnWarning Attribute
      • The failOnRisky Attribute
      • The failOnDeprecation Attribute
      • The failOnPhpunitDeprecation Attribute
      • The failOnPhpunitNotice 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 displayDetailsOnAllIssues Attribute
      • The displayDetailsOnIncompleteTests Attribute
      • The displayDetailsOnSkippedTests Attribute
      • The displayDetailsOnTestsThatTriggerDeprecations Attribute
      • The displayDetailsOnPhpunitDeprecations Attribute
      • The displayDetailsOnPhpunitNotices Attribute
      • The displayDetailsOnTestsThatTriggerErrors Attribute
      • The displayDetailsOnTestsThatTriggerNotices Attribute
      • The displayDetailsOnTestsThatTriggerWarnings Attribute
      • The shortenArraysForExportThreshold Attribute
    • The <testsuites> Element
      • The <testsuite> Element
        • The bootstrap Attribute
        • The phpVersion and phpVersionOperator Attributes
        • The groups Attribute
    • The <source> Element
      • The <include> Element
      • The <exclude> Element
      • The <directory> Element
        • The prefix Attribute
        • The suffix Attribute
      • The <file> Element
      • The <deprecationTrigger> Element
        • The <function> Element
        • The <method> Element
      • 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 <coverage> Element
      • The includeUncoveredFiles Attribute
      • The ignoreDeprecatedCodeUnits Attribute
      • The pathCoverage Attribute
      • The disableCodeCoverageIgnore Attribute
      • The <report> Element
        • The <clover> Element
        • The <cobertura> Element
        • The <crap4j> Element
        • The <html> Element
        • The <php> Element
        • The <text> Element
        • The <xml> Element
    • The <logging> Element
      • The <junit> Element
        • The outputFile Attribute
      • The <teamcity> Element
        • The outputFile Attribute
      • The <testdoxHtml> Element
        • The outputFile Attribute
      • The <testdoxText> Element
        • The outputFile Attribute
    • The <groups> Element
    • The <extensions> Element
      • The <bootstrap> Element
        • The <parameter> Element
    • The <php> Element
      • The <includePath> Element
      • The <ini> Element
      • The <const> Element
      • The <var> Element
      • The <env> Element
      • The <get> Element
      • The <post> Element
      • The <cookie> Element
      • The <server> Element
      • The <files> Element
      • The <request> Element
  • 6. Events
    • Application
    • TestRunner
    • TestSuite
    • Test
  • 7. Copyright
PHPUnit
  • Search


© Copyright 2026, Sebastian Bergmann.