Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
Adds mock handler helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 26, 2016
1 parent c239377 commit ac85c82
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/helpers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?php

use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Handler\MockHandler;

if (!function_exists('dd')) {
/**
* @param array ...$args
Expand All @@ -10,4 +15,21 @@ function dd(...$args)

die();
}
}

if (!function_exists('mock_handler')) {
/**
* @param $stub
*
* @return \GuzzleHttp\Client
*/
function mock_handler($stub)
{
$mock = new MockHandler([
new Response(200, [], $stub)
]);
$handler = HandlerStack::create($mock);

return new Client(['handler' => $handler]);
}
}

0 comments on commit ac85c82

Please sign in to comment.