Skip to content

Commit

Permalink
Tests fixed, and using ClientInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-nitsche committed Jan 31, 2017
1 parent 5435578 commit 7f77e53
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 36 deletions.
8 changes: 2 additions & 6 deletions Tests/Method/DetectorTest.php
Expand Up @@ -28,13 +28,9 @@ protected function setUp()
{
$this->detector = $this->getMock(
'Eko\GoogleTranslateBundle\Translate\Method\Detector',
['getClient'],
['fakeapikey']
null,
['fakeapikey', $this->getClientMock()]
);

$clientMock = $this->getClientMock();

$this->detector->expects($this->any())->method('getClient')->will($this->returnValue($clientMock));
}

/**
Expand Down
8 changes: 2 additions & 6 deletions Tests/Method/LanguagesTest.php
Expand Up @@ -28,13 +28,9 @@ protected function setUp()
{
$this->languages = $this->getMock(
'Eko\GoogleTranslateBundle\Translate\Method\Languages',
['getClient'],
['fakeapikey']
null,
['fakeapikey', $this->getClientMock()]
);

$clientMock = $this->getClientMock();

$this->languages->expects($this->any())->method('getClient')->will($this->returnValue($clientMock));
}

/**
Expand Down
11 changes: 3 additions & 8 deletions Tests/Method/TranslatorTest.php
Expand Up @@ -28,13 +28,9 @@ protected function setUp()
{
$this->translator = $this->getMock(
'Eko\GoogleTranslateBundle\Translate\Method\Translator',
['getClient'],
['fakeapikey', $this->getDetectorMock()]
null,
['fakeapikey', $this->getClientMock(), $this->getDetectorMock()]
);

$clientMock = $this->getClientMock();

$this->translator->expects($this->any())->method('getClient')->will($this->returnValue($clientMock));
}

/**
Expand Down Expand Up @@ -70,8 +66,7 @@ public function testPlainTextTranslate()
// Then
$this->assertEquals($value, "J'ai", 'Should return "J\'ai"');
}



/**
* Test multiple translate method using an array.
*/
Expand Down
19 changes: 9 additions & 10 deletions Translate/Method.php
Expand Up @@ -10,7 +10,7 @@

namespace Eko\GoogleTranslateBundle\Translate;

use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Stopwatch\StopwatchEvent;

Expand All @@ -29,7 +29,7 @@ class Method
protected $apiKey = null;

/**
* @var GuzzleClient A Guzzle client instance
* @var ClientInterface A Guzzle client instance
*/
protected $client;

Expand All @@ -56,22 +56,21 @@ class Method
/**
* Method constructor.
*
* @param string $apiKey API key retrieved from configuration
* @param GuzzleClient $client
* @param Stopwatch $stopwatch Symfony profiler Stopwatch service
* @param string $apiKey API key retrieved from configuration
* @param ClientInterface $client
* @param Stopwatch $stopwatch Symfony profiler Stopwatch service
*/
public function __construct($apiKey, GuzzleClient $client, Stopwatch $stopwatch = null)
public function __construct($apiKey, ClientInterface $client, Stopwatch $stopwatch = null)
{
$this->apiKey = $apiKey;
$this->client = $client;

$this->apiKey = $apiKey;
$this->client = $client;
$this->stopwatch = $stopwatch;
}

/**
* Returns Guzzle HTTP client instance.
*
* @return GuzzleClient
* @return ClientInterface
*/
public function getClient()
{
Expand Down
12 changes: 6 additions & 6 deletions Translate/Method/Translator.php
Expand Up @@ -12,7 +12,7 @@

use Eko\GoogleTranslateBundle\Translate\Method;
use Eko\GoogleTranslateBundle\Translate\MethodInterface;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\ClientInterface;
use Symfony\Component\Stopwatch\Stopwatch;

/**
Expand Down Expand Up @@ -50,12 +50,12 @@ class Translator extends Method implements MethodInterface
/**
* Constructor.
*
* @param string $apiKey Google Translate API key
* @param GuzzleClient $client
* @param Detector $detector A Detector service
* @param Stopwatch $stopwatch Symfony profiler stopwatch service
* @param string $apiKey Google Translate API key
* @param ClientInterface $client
* @param Detector $detector A Detector service
* @param Stopwatch $stopwatch Symfony profiler stopwatch service
*/
public function __construct($apiKey, GuzzleClient $client, Detector $detector, Stopwatch $stopwatch = null)
public function __construct($apiKey, ClientInterface $client, Detector $detector, Stopwatch $stopwatch = null)
{
$this->detector = $detector;

Expand Down

0 comments on commit 7f77e53

Please sign in to comment.