Download the PHP package helmich/phpunit-psr7-assert without Composer

On this page you can find all versions of the php package helmich/phpunit-psr7-assert. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpunit-psr7-assert

PSR-7 assertions for PHPUnit

Unit tests Code Climate Test Coverage

This library adds several new assertions to PHPUnit that allow you to easily and concisely test HTTP request and response messages that implement the PSR-7 interfaces.

Author and copyright

Martin Helmich [email protected] This library is MIT-licensed.

Installation

$ composer require helmich/phpunit-psr7-assert

Compatibility

There are several release branches of this library, each of these being compatible with different releases of PHPUnit and PHP. The following table should give an easy overview:

PSR-7 assertion version PHPUnit 4 PHPUnit 5 PHPUnit 6 PHPUnit 7 PHPUnit 8 PHPUnit 9 PHPUnit 10
v1 (branch v1), unsupported :white_check_mark: :white_check_mark: :no_entry_sign: :no_entry_sign: :no_entry_sign: :no_entry_sign: :no_entry_sign:
v2 (branch v2), unsupported :no_entry_sign: :no_entry_sign: :white_check_mark: :no_entry_sign: :no_entry_sign: :no_entry_sign: :no_entry_sign:
v3 (branch v3), unsupported :no_entry_sign: :no_entry_sign: :no_entry_sign: :white_check_mark: :no_entry_sign: :no_entry_sign: :no_entry_sign:
v4 (branch master) :no_entry_sign: :no_entry_sign: :no_entry_sign: :no_entry_sign: :white_check_mark: :white_check_mark: :white_check_mark:

When you are using composer require and have already declared a dependency to phpunit/phpunit in your composer.json file, Composer should pick latest compatible version automatically.

Usage

Using the Psr7Assertions trait

Simply use the trait Helmich\Psr7Assert\Psr7Assertions in any of your test cases. This trait offers a set of new assert* functions that you can use in your test cases:

Most assertions take a $message argument which is expected to be an instance of the Psr\Http\Message\MessageInterface class -- this means that many assertions work both with request and response messages. These interfaces are defined by the psr/http-message package.

Using the functional interface

This package also offers a functional interface that can be used in a more fluent way than the assertions offered by the Psr7Assertions trait. Simply include the file src/Functions.php for your test cases (preferably, using Composer's autoload-dev setting):

Assertion reference

assertRequestHasUri($request, $uri) / hasUri($uri)

Asserts that the request URI of request $request is equal to $uri

assertMessageHasHeader($message, $header[, $constraint]) / hasHeader($name[, $constraint])

Asserts that the header named $header is present in the HTTP message. The exact behaviour of this assertion is dependent on the $constraint parameter:

  1. If no constraint is given, the assertion will match when the header is present and not empty.
  2. If a primitive value is given as $constraint, the assertion will match when the header is present and is equal to the specified value
  3. If $constraint is an instance of the PHPUnit\Framework\Constraint\Constraint class, the assertion will match when the constraint evaluates to TRUE.

    Example:

assertMessageHasHeaders($message, $constraints) / hasHeaders($constraints)

Same as assertMessageHasHeader, just with multiple headers. $constraints is a key-value array using header names as keys and constraints (see above) as values.

Example:

assertMessageBodyMatches($message, $constraint) / bodyMatches($constraint)

Asserts that the message body matches the constraint $constraint. If $constraint is a primitive value, the assertion will pass when the message body is equal to the constraint. If $constraint is an instance of the PHPUnit\Framework\Constraint\Constraint class, the constraint will be evaluated as-is.

assertMessageBodyMatchesJson($message, $jsonConstraints) / bodyMatchesJson($jsonConstraints)

This actually asserts several facts:

  1. The message must have a content-type header that is equal to application/json
  2. The message body must be a valid JSON string (that means decodeable by json_decode)
  3. The encoded JSON object must match all constraints specified in the $jsonConstraints array. For this, the helmich/phpunit-json-assert package will be used.
assertMessageBodyMatchesForm($message, $formConstraints) / bodyMatchesForm($formConstraints)

This asserts that the message body contains application/x-www-form-urlencoded-encoded content, with individual variables matching the $formConstraints array.

assertRequestHasMethod($request, $method) / hasMethod($method)

Asserts that the request has the method $method. For the most common request method, shorthand assertions are available:

assertResponseHasStatus($response, $status) / hasStatus($status)

Asserts that the response status matches a given constraint. If $status is a scalar value, this assertion will check for equality.

For the most common checks, some shorthand assertions are available:

assertStringIsAbsoluteUri($uri) / isAbsoluteUri()

Assert that the string $uri contains a valid absolute URL (scheme and hostname are required).

assertHasQueryParameter($uriOrRequest, $name[, $value]) / hasQueryParameter($name[, $value])

Asserts that an URI contains a query parameter matching the given constraints. $name and $value may both be string values as well as instances of the PHPUnit\Framework\Constraint\Constraint interface.

The $uriOrRequest value may be


All versions of phpunit-psr7-assert with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
helmich/phpunit-json-assert Version ^3.4
psr/http-message Version ^1.1 || ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package helmich/phpunit-psr7-assert contains the following files

Loading the files please wait ....