1. Go to this page and download the library: Download gromatics/http-fixtures 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/ */
namespace Tests\Fixtures;
use Gromatics\HttpFixtures\HttpFixture;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
class ExampleHttpFixture extends HttpFixture
{
public function definition(): array
{
return [
'status' => Arr::random(['OK', 'NOK']),
'message' => $this->faker->sentence,
'items' => [
[
'identifier' => Str::random(20),
'name' => $this->faker->company,
'address' => $this->faker->address,
'postcode' => $this->faker->postcode,
'city' => $this->faker->city,
'country' => $this->faker->country,
'phone' => $this->faker->phoneNumber,
'email' => $this->faker->email,
]
],
];
}
}
use Gromatics\Httpfixtures\Services\HttpResponseRecorder;
use Illuminate\Support\Facades\Http;
it('creates a HTTP Fixture from a real JSON request', function () {
Http::record();
Http::get('https://api.stackexchange.com/2.2/search?order=desc&sort=activity&intitle=perl&site=stackoverflow&limit=1');
HttpResponseRecorder::recordedToHttpFixture();
});