diff --git a/Resources/config/methods.xml b/Resources/config/methods.xml
index 5e18893..63835f3 100644
--- a/Resources/config/methods.xml
+++ b/Resources/config/methods.xml
@@ -4,6 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
+
+ GuzzleHttp\Client
+
+
@@ -21,19 +25,26 @@
%eko_google_translate.api_key%
+
%eko_google_translate.api_key%
+
%eko_google_translate.api_key%
+
+
+
+
+
diff --git a/Tests/Method/DetectorTest.php b/Tests/Method/DetectorTest.php
index 0478554..b1feaf8 100644
--- a/Tests/Method/DetectorTest.php
+++ b/Tests/Method/DetectorTest.php
@@ -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));
}
/**
diff --git a/Tests/Method/LanguagesTest.php b/Tests/Method/LanguagesTest.php
index ae15c7d..75f0184 100644
--- a/Tests/Method/LanguagesTest.php
+++ b/Tests/Method/LanguagesTest.php
@@ -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));
}
/**
diff --git a/Tests/Method/TranslatorTest.php b/Tests/Method/TranslatorTest.php
index 6929412..8dca3e8 100644
--- a/Tests/Method/TranslatorTest.php
+++ b/Tests/Method/TranslatorTest.php
@@ -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));
}
/**
@@ -70,8 +66,7 @@ public function testPlainTextTranslate()
// Then
$this->assertEquals($value, "J'ai", 'Should return "J\'ai"');
}
-
-
+
/**
* Test multiple translate method using an array.
*/
diff --git a/Translate/Method.php b/Translate/Method.php
index ff22a7a..69b23e3 100644
--- a/Translate/Method.php
+++ b/Translate/Method.php
@@ -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;
@@ -29,7 +29,7 @@ class Method
protected $apiKey = null;
/**
- * @var GuzzleClient A Guzzle client instance
+ * @var ClientInterface A Guzzle client instance
*/
protected $client;
@@ -54,23 +54,23 @@ class Method
protected $counter = 1;
/**
- * Constructor.
+ * Method constructor.
*
- * @param string $apiKey API key retrieved from configuration
- * @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, Stopwatch $stopwatch = null)
+ public function __construct($apiKey, ClientInterface $client, Stopwatch $stopwatch = null)
{
- $this->apiKey = $apiKey;
- $this->client = new GuzzleClient();
-
+ $this->apiKey = $apiKey;
+ $this->client = $client;
$this->stopwatch = $stopwatch;
}
/**
* Returns Guzzle HTTP client instance.
*
- * @return GuzzleClient
+ * @return ClientInterface
*/
public function getClient()
{
diff --git a/Translate/Method/Translator.php b/Translate/Method/Translator.php
index 60fcfb0..66a8e6e 100644
--- a/Translate/Method/Translator.php
+++ b/Translate/Method/Translator.php
@@ -12,6 +12,7 @@
use Eko\GoogleTranslateBundle\Translate\Method;
use Eko\GoogleTranslateBundle\Translate\MethodInterface;
+use GuzzleHttp\ClientInterface;
use Symfony\Component\Stopwatch\Stopwatch;
/**
@@ -49,15 +50,16 @@ class Translator extends Method implements MethodInterface
/**
* Constructor.
*
- * @param string $apiKey Google Translate API key
- * @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, Detector $detector, Stopwatch $stopwatch = null)
+ public function __construct($apiKey, ClientInterface $client, Detector $detector, Stopwatch $stopwatch = null)
{
$this->detector = $detector;
- return parent::__construct($apiKey, $stopwatch);
+ return parent::__construct($apiKey, $client, $stopwatch);
}
/**