Skip to content
This repository has been archived by the owner on May 17, 2022. It is now read-only.

Commit

Permalink
Inject the GuzzleHttp\ClientInterface instead of the concrete class i…
Browse files Browse the repository at this point in the history
…n the RpcClient constructor
  • Loading branch information
cyb3rd4d committed Jan 13, 2016
1 parent 818b552 commit 9a98dc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/RpcClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

namespace Martial\Transmission\API;

use GuzzleHttp\Client;
use GuzzleHttp\ClientInterface;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\RequestException;
use Martial\Transmission\API\Argument\Torrent\Add;

class RpcClient implements TransmissionAPI
{
/**
* @var Client
* @var ClientInterface
*/
private $httpClient;

Expand All @@ -27,11 +27,11 @@ class RpcClient implements TransmissionAPI
/**
* RpcClient constructor.
*
* @param Client $httpClient
* @param ClientInterface $httpClient
* @param string $rpcUsername
* @param string $rpcPassword
*/
public function __construct(Client $httpClient, $rpcUsername, $rpcPassword)
public function __construct(ClientInterface $httpClient, $rpcUsername, $rpcPassword)
{
$this->httpClient = $httpClient;
$this->rpcUsername = $rpcUsername;
Expand Down Expand Up @@ -501,7 +501,7 @@ private function sendRequest($sessionId, $requestBody)
try {
$response = $this
->httpClient
->post('', [
->request('POST', '', [
'body' => $requestBody,
'auth' => [$this->rpcUsername, $this->rpcPassword],
'headers' => [
Expand Down
16 changes: 9 additions & 7 deletions tests/RpcClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class RpcClientTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->guzzle = m::mock('\GuzzleHttp\Client');
$this->guzzle = m::mock('\GuzzleHttp\ClientInterface');
$this->guzzleResponse = m::mock('\Psr\Http\Message\ResponseInterface');
$this->sessionId = uniqid();
$this->rpcClient = new RpcClient($this->guzzle, self::RPC_USERNAME, self::RPC_PASSWORD);
Expand Down Expand Up @@ -1774,13 +1774,15 @@ private function sendRequest($requestBody, $sessionId = '')

return $this
->guzzle
->shouldReceive('post')
->shouldReceive('request')
->once()
->with('', [
'body' => $requestBody,
'auth' => [self::RPC_USERNAME, self::RPC_PASSWORD],
'headers' => [
'X-Transmission-Session-Id' => $sessionId
->withArgs([
'POST',
'',
[
'body' => $requestBody,
'auth' => [self::RPC_USERNAME, self::RPC_PASSWORD],
'headers' => ['X-Transmission-Session-Id' => $sessionId]
]
]);
}
Expand Down

0 comments on commit 9a98dc0

Please sign in to comment.