PHPackages                             stein197/phpunit-extended - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. stein197/phpunit-extended

ActiveLibrary[Testing &amp; Quality](/categories/testing)

stein197/phpunit-extended
=========================

Extended PHPUnit assertions

3.0.0(10mo ago)725MITPHPPHP &gt;=8.4CI passing

Since Apr 19Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/stein197/phpunit-extended)[ Packagist](https://packagist.org/packages/stein197/phpunit-extended)[ RSS](/packages/stein197-phpunit-extended/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

[![](https://camo.githubusercontent.com/15124c88f3ca3308151b681ee50077438f12629768b41f76f162727becf86756/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737465696e3139372f706870756e69742d657874656e646564)](https://camo.githubusercontent.com/15124c88f3ca3308151b681ee50077438f12629768b41f76f162727becf86756/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737465696e3139372f706870756e69742d657874656e646564)[![](https://camo.githubusercontent.com/39d488a24022586e33be645ee19cf4d255448f2e99d70180580323e47ec9358d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737465696e3139372f706870756e69742d657874656e6465642f746573742e796d6c)](https://camo.githubusercontent.com/39d488a24022586e33be645ee19cf4d255448f2e99d70180580323e47ec9358d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f737465696e3139372f706870756e69742d657874656e6465642f746573742e796d6c)

PHPUnit Extended
================

[](#phpunit-extended)

This package is a small extension to PHPUnit that extends its assertions. The library provides assertions for PSR-7 HTTP responses, XML/HTML documents and JSON structures. The extension uses the following libraries to make it work:

- [DOM](https://www.php.net/manual/en/book.dom.php): the new native PHP 8.4 DOM library to make assertions against XML/HTML DOM structures
- [PSR-7](https://www.php-fig.org/psr/psr-7/): HTTP message interfaces to make assertions against HTTP server response objects
- [JSONPath](https://github.com/Galbar/JsonPath-PHP): JSONPath library to make assertions against JSON structures

Installation
------------

[](#installation)

```
$ composer require --dev stein197/phpunit-extended
```

Usage
-----

[](#usage)

Let's say you test a an HTTP response:

```
namespace Test;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Stein197\PHPUnit\ExtendedTextCase; // Trait that extends the basic PHPUnit assertion functionality and implements the ExtendedTestCaseInterface interface
use Stein197\PHPUnit\ExtendedTestCaseInterface;

// Your test class
final class ResponseTest extends TestCase implements ExtendedTestCaseInterface {

	use ExtendedTextCase; // Include the extended assertions

	#[Test]
	public function testResponse(): void {
		// HTTP response assertions
		$response = $this->request('/home'); // Anything that returns a PSR-7 response object
		$response = $this->createResponseAssertion($response); // Wrap the PSR-7 response in an assertion object
		$response->assertOk(); // Assert the status code is 200
		$response->assertHeaderEquals('Content-Type', 'text/html'); // Assert that there is a header 'Content-Type' with the value 'text/html'
		// ...

		// XML/HTML DOM assertions
		$document = $response->document(); // Return a DocumentAssert assertion object containing the response body
		$document->query('#main h1')->assertTextEquals('Hello, World!'); // Query elements by query selector an assert
		$document->xpath('//*[@id = "main"]//h1')->assertTextEquals('Hello, World!'); // The the same but using XPath
		// ...

		// JSON assertions
		$json = $response->createJsonAssertion(); // Return a JsonAssert containing the response body
		$json->assertExists('$.user'); // Assert that there is a given JSONPath
		// ...

		$this->createJsonAssertion('{...}'); // Wrap a JSON string
		$this->createHtmlAssertion(('...'); // Wrap an HTML string
		$this->createXmlAssertion(('...'); // Wrap an XML string
	}
}
```

> **IMPORTANT!**
>
> The extension uses instances of the `PHPUnit\Framework\TestCase` class. The methods cannot be called statically like the native PHPUnit's methods:
>
> ```
> self::assertOk(); // Won't work
> ```

Testing
-------

[](#testing)

Run `make test`.

Documentation
-------------

[](#documentation)

The main methods of the trait are:

- `createResponseAssertion(ResponseInterface $response): ResponseAssert`: Wraps an HTTP response object in an assertion one
- `createJsonAssertion(string $json): JsonAssert`: Wraps a JSON string in an assertion object
- `createHtmlAssertion(string $html): DocumentAssert`: Wraps an HTML string in an assertion object
- `createXmlAssertion(string $xml): DocumentAssert`: Wraps an XML string in an assertion object
- `pass(): void`: Marks test as passed

The whole documentation to every assertion method can be found in the phpdoc comments in the source code.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance56

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 59% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~30 days

Total

4

Last Release

301d ago

Major Versions

1.0.0 → 2.0.02025-05-18

2.0.1 → 3.0.02025-07-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/d8311ee6555571454bfa02135422b055fa0c19f360c827e9990535c9b140f81f?d=identicon)[stein197](/maintainers/stein197)

---

Top Contributors

[![stein197](https://avatars.githubusercontent.com/u/35802538?v=4)](https://github.com/stein197 "stein197 (59 commits)")[![ngafarov](https://avatars.githubusercontent.com/u/207839278?v=4)](https://github.com/ngafarov "ngafarov (41 commits)")

### Embed Badge

![Health badge](/badges/stein197-phpunit-extended/health.svg)

```
[![Health](https://phpackages.com/badges/stein197-phpunit-extended/health.svg)](https://phpackages.com/packages/stein197-phpunit-extended)
```

###  Alternatives

[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M32](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M775](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
