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
    • Data Providers
    • Testing Output
    • Incomplete Tests
    • Skipping Tests
      • Skipping Tests using Attributes
    • Test Dependencies
    • Failure Output
      • Edge Cases
  • 3. The Command-Line Test Runner
    • Outcome and Issues
    • Command-Line Options
      • Configuration
      • Selection
      • Execution
        • Isolation
        • Risky Tests
        • Automatically stop when …
        • Exit with error code when …
        • Test Result Cache
        • Test Order
      • Reporting
        • Console
        • Progress and Result Printing
        • Details about Issues
        • Alternative Output
      • Logging
        • Code Coverage
        • Miscellaneous
  • 4. Organizing Tests
    • Composing a Test Suite Using the Filesystem
    • Composing a Test Suite Using XML Configuration
  • 5. Fixtures
    • More setUp() than tearDown()
    • Sharing Fixture
    • Global State
  • 6. Test Doubles
    • Test Stubs
      • Creating Test Stubs
        • createStub()
        • createStubForIntersectionOfInterfaces()
        • createConfiguredStub()
      • Configuring Test Stubs
        • willReturn()
        • willThrowException()
        • willReturnArgument()
        • willReturnCallback()
        • willReturnSelf()
        • willReturnMap()
        • Get-Hooked Properties
    • Mock Objects
      • Creating Mock Objects
        • createMock()
        • createMockForIntersectionOfInterfaces()
        • createConfiguredMock()
      • Configuring Mock Objects
    • MockBuilder API
      • setConstructorArgs()
      • disableOriginalConstructor()
      • disableOriginalClone()
      • disableAutoReturnValueGeneration()
      • onlyMethods()
      • getMock()
      • Set-Hooked Properties
  • 7. Code Coverage
    • Software Metrics for Code Coverage
    • Including Files
    • Targeting Units of Code
    • Ignoring Code Blocks
  • 8. Risky Tests
    • Useless Tests
    • Unintentionally Covered Code
    • Output During Test Execution
    • Test Execution Timeout
    • Global State Manipulation
  • 9. Error Handling
    • Limiting issues to “your code”
    • Ignoring issue suppression
    • Ignoring previously reported issues
    • Expecting Deprecations (E_USER_DEPRECATED)
    • Disabling PHPUnit’s error handler
  • 10. Extending PHPUnit
    • Enhancing concrete test cases
    • Extracting abstract test cases
    • Extracting traits
    • 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
    • TestDox
    • DisableReturnValueGenerationForTestDoubles
    • DoesNotPerformAssertions
    • IgnoreDeprecations
    • WithoutErrorHandler
    • Code Coverage
      • CoversClass
      • CoversClassesThatImplementInterface
      • CoversClassesThatExtendClass
      • CoversTrait
      • CoversMethod
      • CoversFunction
      • CoversNothing
      • UsesClass
      • UsesClassesThatImplementInterface
      • UsesClassesThatExtendClass
      • UsesTrait
      • UsesMethod
      • UsesFunction
    • Data Provider
      • DataProvider
      • DataProviderExternal
      • TestWith
      • TestWithJson
    • Test Dependencies
      • Depends
      • DependsUsingDeepClone
      • DependsUsingShallowClone
      • DependsExternal
      • DependsExternalUsingDeepClone
      • DependsExternalUsingShallowClone
      • DependsOnClass
      • DependsOnClassUsingDeepClone
      • DependsOnClassUsingShallowClone
    • 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
    • Skipping Tests
      • RequiresPhp
      • RequiresPhpExtension
      • RequiresSetting
      • RequiresPhpunit
      • RequiresPhpunitExtension
      • RequiresFunction
      • RequiresMethod
      • RequiresOperatingSystem
      • RequiresOperatingSystemFamily
      • RequiresEnvironmentVariable
  • 3. Events
    • Application
    • TestRunner
    • TestSuite
    • Test
  • 4. 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 <testsuites> Element
      • The <testsuite> Element
    • 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
  • 5. Copyright
PHPUnit
  • Search


© Copyright 2025, Sebastian Bergmann.