Google\Cloud\Tests\Translate\TranslateTestClient::setConnection PHP Method

setConnection() public method

public setConnection ( $connection )
    public function setConnection($connection)
    {
        $this->connection = $connection;
    }

Usage Example

 public function testTranslateBatch()
 {
     $expected1 = $this->getTranslateExpectedData('translate', 'translated', 'en');
     $expected2 = $this->getTranslateExpectedData('translate2', 'translated2', 'en');
     $stringsToTranslate = [$expected1['input'], $expected2['input']];
     $target = 'de';
     $this->connection->listTranslations(['target' => $target, 'q' => $stringsToTranslate, 'key' => $this->key, 'model' => 'base'])->willReturn(['data' => ['translations' => [$this->getTranslateApiData($expected1['text'], $expected1['source']), $this->getTranslateApiData($expected2['text'], $expected2['source'])]]])->shouldBeCalledTimes(1);
     $client = new TranslateTestClient(['key' => $this->key, 'target' => $target]);
     $client->setConnection($this->connection->reveal());
     $translations = $client->translateBatch($stringsToTranslate, ['model' => 'base']);
     $this->assertEquals($expected1, $translations[0]);
     $this->assertEquals($expected2, $translations[1]);
 }
TranslateTestClient