1. Go to this page and download the library: Download bbrothers/muzzle 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/ */
$client = new Muzzle;
$expectations = [];
for ($i = 0; $i < 10; $i++) {
$expectations[] = (new Expectation)
->get("users/{$i}")
->replyWith((new ResponseBuilder)->setJson(['number' => $i]));
}
$client->append(...$expectations);
class ContainJson implements Assertion {
public function __consturct(array $content)
{
$this->expected = $expected;
}
public function __invoke(AssertableRequest $actual) : void
{
$actual->assertJson($this->expected);
}
}
// then
(new Expectation)->should(new ContainJson(['name' => 'Jane Doe']));
$expected = ['name' => 'Jane Doe'];
(new Expectation)->should(function (AssertableRequest $actual) use ($expected) : void {
$actual->assertJson($expected);
});