PHPackages                             oscarotero/psr7-unitesting - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. oscarotero/psr7-unitesting

AbandonedArchivedLibrary[HTTP &amp; Networking](/categories/http)

oscarotero/psr7-unitesting
==========================

Library to tests psr-7 compatible classes

v3.0.1(9y ago)5263MITPHPPHP &gt;=5.5

Since Aug 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/oscarotero/psr7-unitesting)[ Packagist](https://packagist.org/packages/oscarotero/psr7-unitesting)[ Docs](https://github.com/oscarotero/psr7-unitesting)[ RSS](/packages/oscarotero-psr7-unitesting/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (7)Versions (7)Used By (0)

psr7-unitesting
===============

[](#psr7-unitesting)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/d957bdacaf64881b3cd3119e07bf4ef61c20725458ab79d0802497bce070ec26/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f736361726f7465726f2f707372372d756e6974657374696e672f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/oscarotero/psr7-unitesting/?branch=master)[![Build Status](https://camo.githubusercontent.com/77ed0c97e3d7855732b8d6c08d4b7510e5070aaebb2781043c399710fefbb1c1/68747470733a2f2f7472617669732d63692e6f72672f6f736361726f7465726f2f707372372d756e6974657374696e672e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/oscarotero/psr7-unitesting)

Simple library to execute unit tests in [psr-7](http://www.php-fig.org/psr/psr-7/) compatible http messages.

It uses [symfony/dom-crawler](https://github.com/symfony/DomCrawler) and [symfony/css-selector](https://github.com/symfony/CssSelector) library to parse and test the html in the body. And [Guzzle](https://github.com/guzzle/guzzle) as http client

This package provides a binary java file with the w3c vnu validator (to validate html) but you can use the REST api (slower) if you don't have (or don't want to have) java installed.

Usage example:
--------------

[](#usage-example)

```
use Psr7Unitesting\Assert;

class AppTest extends PHPUnit_Framework_TestCase
{
	public function testRemote()
	{
		//Execute a GET request and assert the response:

		Assert::get('http://example.com')
			->statusCode(200)
			->header('Content-Type', 'text/html')
			->hasHeader('Cache-Control')
			->hasNotHeader('Expires')

			->assertBody()
				->isReadable()
				->isSeekable()
				->end() //back to Response

			->assertHtml()
				->isValid() //use w3c vnu validator
				->has('meta[property="og:title"]')
				->hasNot('blink')
				->contains('a.home-link', 'Go to home')
				->notContains('p', '') //empty paragraphs

				//Execute more tests for each element individually
				->map('img', function ($img) {
					$this->assertNotEmpty($img->attr('alt'));
				});
	}

	public function testLocal()
	{
		//Assert local psr-7 instances
		$app = new App();
		$response = $app->dispatch('/post/34');

		Assert::create($response)
			->statusCode(200);
	}
}
```

Available assertions:
---------------------

[](#available-assertions)

### Message

[](#message)

methoddescription`hasHeader`Asserts that a header exists`hasNotHeader`Asserts that a header does not exists`header`Asserts that a header has a specific value`protocolVersion`Asserts the protocol version of the message`body`Asserts the body content (as string)`assertBody`Returns a `Stream` assertion instance### Request

[](#request)

Extends `Message` with the following additions:

methoddescription`method`Asserts the method value`requestTarget`Asserts the request target value`uri`Asserts the uri value (as string)`assertUri`Returns a `Uri` assertion instance### ServerRequest

[](#serverrequest)

Extends `Request` with the following additions:

methoddescription`hasServerParam`Asserts that a server param exists`serverParam`Asserts a server param value`hasCookieParam`Asserts that a cookie param exists`cookieParam`Asserts a cookie param value`hasQueryParam`Asserts that a query param exists`queryParam`Asserts a query param value`hasUploadedFile`Asserts that an uploaded file exists`hasParsedBody`Asserts that a param exists in the parsed body`parsedBody`Asserts a value in the parsed body`hasAttribute`Asserts that an attribute exists`attribute`Asserts an attribute value### Response

[](#response)

Extends `Message` with the following additions:

methoddescription`statusCode`Asserts the status code value`reasonPhrase`Asserts the reason pharase value`assertHtml`Returns a `Html` assertion instance### Uri

[](#uri)

methoddescription`scheme`Asserts the scheme value`authority`Asserts the authority value`userInfo`Asserts the user info value`host`Asserts the host value`port`Asserts the port value`path`Asserts the path value`query`Asserts the query value`fragment`Asserts the fragment value### Stream

[](#stream)

methoddescription`size`Asserts the stream size`isSeekable`Asserts that the stream is seekable`isNotSeekable`Asserts that the stream is not seekable`isWritable`Asserts that the stream is writable`isNotWritable`Asserts that the stream is not writable`isReadable`Asserts that the stream is readable`isNotReadable`Asserts that the stream is not readable`assertHtml`Returns a `Html` assertion instance### Html

[](#html)

methoddescription`count`Asserts the number of elements matching with the selector`has`Asserts there is at least one element matching with the selector`hasNot`Asserts there is not any element matching with the selector`contains`Asserts there is at least one element matching with the selector containing the text`notContains`Asserts there is not any element matching with the selector and containing the text`isValid`Asserts the html value is w3c standard`map`Execute a callback for each element selected

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~55 days

Recently: every ~60 days

Total

6

Last Release

3634d ago

Major Versions

v1.2.0 → v2.0.02016-05-04

v2.0.0 → v3.0.02016-05-28

PHP version history (2 changes)v1.2.0PHP &gt;=5.4

v2.0.0PHP &gt;=5.5

### Community

Maintainers

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

---

Top Contributors

[![oscarotero](https://avatars.githubusercontent.com/u/377873?v=4)](https://github.com/oscarotero "oscarotero (32 commits)")

---

Tags

httppsr-7psr-messagesunitesting

### Embed Badge

![Health badge](/badges/oscarotero-psr7-unitesting/health.svg)

```
[![Health](https://phpackages.com/badges/oscarotero-psr7-unitesting/health.svg)](https://phpackages.com/packages/oscarotero-psr7-unitesting)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

8.0k1.0B3.2k](/packages/guzzlehttp-psr7)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k692.9M1.9k](/packages/psr-http-factory)[symfony/psr-http-message-bridge

PSR HTTP message bridge

1.3k296.6M805](/packages/symfony-psr-http-message-bridge)[php-http/message

HTTP Message related tools

1.3k263.9M678](/packages/php-http-message)[league/uri-interfaces

Common tools for parsing and resolving RFC3987/RFC3986 URI

538204.9M23](/packages/league-uri-interfaces)[laminas/laminas-diactoros

PSR HTTP Message implementations

546105.8M964](/packages/laminas-laminas-diactoros)

PHPackages © 2026

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