コード例 #1
0
 /**
  * Create an instance of Client with default dependencies
  * automatically created (for use by people without DI)
  *
  * @param string $apiKey
  * @param CacheInterface $cache
  * @return Client
  */
 public static function create($apiKey, $cache = null)
 {
     $requestFactory = new RequestFactory();
     $rowFactory = new RowFactory();
     $resultFactory = new ResultFactory($rowFactory);
     $responseParser = new ResponseParser();
     $urlBuilder = new UrlBuilder();
     $guzzle = new Guzzle();
     $client = new Client($apiKey, $requestFactory, $resultFactory, $responseParser, $urlBuilder, $guzzle);
     if (isset($cache)) {
         $client->setCache($cache);
     }
     return $client;
 }
コード例 #2
0
ファイル: ClientTest.php プロジェクト: silktide/semrush-api
 public function testCache()
 {
     $this->doSetup(2);
     $result = $this->getMockBuilder('Silktide\\SemRushApi\\Model\\Result')->disableOriginalConstructor()->getMock();
     $cache = $this->getMock('Silktide\\SemRushApi\\Cache\\CacheInterface');
     $cache->expects($this->exactly(2))->method('cache');
     $cache->expects($this->exactly(2))->method('fetch')->willReturnOnConsecutiveCalls(null, $result);
     $this->resultFactory->expects($this->exactly(1))->method('create')->willReturn($result);
     $this->instance->setCache($cache);
     $resultOne = $this->instance->getDomainAdwordsUnique('domain.com', []);
     $resultTwo = $this->instance->getDomainAdwordsUnique('domain.com', []);
     $this->assertEquals($resultOne, $resultTwo);
 }