Exemple #1
0
 /**     
  * @View()          
  */
 public function getTranslationAction(Request $request)
 {
     $browser = new Browser(new Curl());
     //$browser->getClient()->setVerifyPeer(false);
     $clientId = '88b2226a-d8fe-4ec0-a22b-f43446575ba4';
     $clientSecret = 'UC92IU1JhnFYpFQE43+M9TLuPX1Z3pZZX7xuH/EHNyU=';
     $query = $request->query->get('q');
     $accessTokenProvider = new AccessTokenProvider($browser, $clientId, $clientSecret);
     $translator = new MicrosoftTranslator($browser, $accessTokenProvider);
     $translatedString = $translator->translate('This is a test', 'uk');
     return [];
 }
 public function testCachedBrowserClient()
 {
     $currentClient = $this->browser->getClient();
     $arrayCache = new ArrayCache();
     $cachedClient = new CachedClient($currentClient, $arrayCache);
     $this->browser->setClient($cachedClient);
     for ($i = 1; $i <= 3; $i++) {
         $this->translator->translate('This is a test', 'nl');
     }
     $this->assertLessThanOrEqual(2, $cachedClient->getMisses());
     // at most one for the access token, one for the translation
     $this->assertSame(2, $cachedClient->getHits());
     $this->browser->setClient($currentClient);
 }