mercredi 2 mai 2018

How to Mock a Guzzle Request for PHPUnit

I have a class like this:

class CategoryClient
{
    private $categories;

    /**
     * Constructor
     * Retrieves JSON File
     */
    public function __construct(Client $client)
    {
        $response = $client->request('GET', config('services.url'));
        $this->categories = collect(json_decode($response->getBody(), true));
    }
}

How would I mock the json response for testing purposes in PHPUnit? and set the $this->categories variable?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire