Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds traits for better abstraction, hopefully
- Loading branch information
1 parent
ce1492b
commit 7a53ae8
Showing
5 changed files
with
57 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Shutterstock\Api; | ||
|
||
trait MockClientTrait { | ||
protected function getClient() { | ||
return new Client('client_id', 'client_secret'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Shutterstock\Api; | ||
|
||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\Psr7\Response; | ||
|
||
trait MockHandlerTrait { | ||
protected function getMockHandler(Response $response = null) { | ||
if (is_null($response)) { | ||
$response = new Response(200, [], json_encode([])); | ||
} | ||
return new MockHandler([$response]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Shutterstock\Api; | ||
|
||
use GuzzleHttp\Client as Guzzle; | ||
use GuzzleHttp\Handler\MockHandler; | ||
use GuzzleHttp\HandlerStack; | ||
use ReflectionClass; | ||
|
||
trait SetMockHandlerTrait { | ||
protected function setGuzzleWithMockHandler(Client $client, MockHandler $mockHandler) { | ||
$options = [ | ||
'handler' => HandlerStack::create($mockHandler), | ||
]; | ||
$reflectedClient = new ReflectionClass($client); | ||
$reflectedProperty = $reflectedClient->getProperty('guzzle'); | ||
$reflectedProperty->setAccessible(true); | ||
$reflectedProperty->setValue($client, new Guzzle($options)); | ||
return true; | ||
} | ||
} |