PHP code example of bauhaus / assert-psr-response
1. Go to this page and download the library: Download bauhaus/assert-psr-response library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bauhaus / assert-psr-response example snippets
use Bauhaus\PsrResponseAssertion\PsrResponseAssertion;
use Bauhaus\PsrResponseAssertion\Matchers\HeaderLine;
use Bauhaus\PsrResponseAssertion\Matchers\StatusCode;
$assertion = PsrResponseAssertion::with(
StatusCode::equalTo(200),
HeaderLine::equalTo('Content-Type', 'application/json')
);
$psrResponse = // retrieve it from somewhere ...
$psrResponse = $psrResponse
->withStatus(404)
->withHeader('Content-Type', 'text/html');
$assertion->assert($psrResponse);
// throw PsrResponseAssertionException with message:
// Actual response status code '404' is not equal to the expected '200'
// Actual response header line 'Content-Type' 'text/html' is not equal to the expected 'application/json'