/**
  * Fetches data from service
  *
  * @return array
  */
 protected function fetch()
 {
     try {
         $data = $this->adapter->fetchStatistic($this->pm->getInstalledPackages());
     } catch (\Exception $e) {
         $data = [];
     }
     return $data;
 }
 /**
  * @dataProvider statisticProvider
  *
  * @param array $expectedResult
  * @param array $fetchedData
  * @param int   $code
  * @param bool  $exceptionExpected
  */
 public function testFetchStatistic($expectedResult, $fetchedData, $code = Codes::HTTP_OK, $exceptionExpected = false)
 {
     $this->client->expects($this->once())->method('createRequest')->will($this->returnValue($this->request));
     $this->request->expects($this->once())->method('send')->will($this->returnValue($this->response));
     $this->request->expects($this->any())->method('getQuery')->will($this->returnValue($this->query));
     $this->response->expects($this->once())->method('getStatusCode')->will($this->returnValue(200));
     $this->response->expects($this->once())->method('json')->will($this->returnValue($fetchedData));
     if ($exceptionExpected) {
         $this->setExpectedException($exceptionExpected);
     }
     $result = $this->adapter->fetchStatistic();
     $this->assertEquals($expectedResult, $result);
 }
 /**
  * @dataProvider getProvider
  *
  * @param mixed $cachedData
  * @param array $resultExpected
  * @param bool  $fetchExpected
  * @param array $fetchedResult
  * @param bool  $isException
  */
 public function testGet($cachedData, $resultExpected, $fetchExpected, $fetchedResult = [], $isException = false)
 {
     $this->cache->expects($this->once())->method('fetch')->with($this->equalTo(TranslationStatisticProvider::CACHE_KEY))->will($this->returnValue($cachedData));
     if ($fetchExpected) {
         if ($isException) {
             $this->adapter->expects($this->once())->method('fetchStatistic')->will($this->throwException($fetchedResult));
         } else {
             $this->adapter->expects($this->once())->method('fetchStatistic')->will($this->returnValue($fetchedResult));
         }
         $this->cache->expects($this->once())->method('save')->with($this->equalTo(TranslationStatisticProvider::CACHE_KEY));
     } else {
         $this->adapter->expects($this->never())->method('fetchStatistic');
     }
     $result = $this->provider->get();
     $this->assertSame($resultExpected, $result);
 }