1. Go to this page and download the library: Download helmich/phpunit-psr7-assert 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/ */
helmich / phpunit-psr7-assert example snippets
use Helmich\Psr7Assert\Psr7Assertions;
use PHPUnit\Framework\Testcase;
class MyTestCase extends Testcase
{
use Psr7Assertions;
public function testRequestMatchesExpectations()
{
$request = /* build some instance of Psr\Http\Message\MessageInterface */;
$this->assertRequestHasUri($request, '/foo');
$this->assertRequestIsPost($request);
$this->assertMessageHasHeaders($request, [
'content-type' => 'application/json',
'expect' => '202-accepted'
]);
$this->assertMessageBodyMatchesJson($request, [
'$.username' => 'mhelmich'
]);
}
}
public function testRequestMatchesExpectations()
{
$request = /* build some instance of Psr\Http\Message\MessageInterface */;
assertThat($request, logicalAnd(
hasUri('/foo'),
isPost(),
hasHeaders([
'content-type' => 'application/json',
'expect' => '202-accepted'
]),
bodyMatchesJson(['$.username' => 'mhelmich'])
));
}