/**
  * @test
  */
 public function doNotInsertWhenValuesAreadyExist()
 {
     $countryMap = new CountryMap();
     $service = new DatacenterService($this->dao, $countryMap);
     $service->insertValues($this->inputFile, 1, 1, 1, 1, 1);
     $dataParam = new DataParam(1, 1, 1, 1, 1, 1);
     $this->assertEquals(2, $service->getValuesWithSimpleFilter($dataParam)->count());
     $this->emptyDatabase();
     $file = __DIR__ . "/Teste.xls";
     $this->spreadsheetReader = new Spreadsheet_Excel_Reader($file);
     $this->inputFile->setNewSpreadsheet($this->spreadsheetReader);
     $service->insertValues($this->inputFile, 1, 1, 1, 1, 1);
     $dataParam_2 = new DataParam(1, 1, 1, 1, 1, 1);
     $this->assertEquals(4, $service->getValuesWithSimpleFilter($dataParam_2)->count());
 }
 private function stubDatacenterService()
 {
     $this->dataCenterService->expects($this->any())->method('getValuesWithSimpleFilter')->will($this->returnValue(new ArrayIterator()));
     $this->dataCenterService->expects($this->at(0))->method('getValuesFilteringWithMultipleParams')->will($this->returnValue(new ArrayIterator()));
     $map = new HashMap();
     $map->put(0, new ArrayIterator());
     $map->put(1, new ArrayIterator());
     $this->dataCenterService->expects($this->at(1))->method('getValuesFilteringWithMultipleParams')->will($this->returnValue($map));
 }
 public function getValuesWithMultipleParams(DataParam $params, array $years)
 {
     $values = $this->datacenterService->getValuesFilteringWithMultipleParams($params, $years);
     if ($this->asJson) {
         if ($values instanceof HashMap) {
             return $this->hashMapFilteredToJSON($values);
         }
         return $this->toJson($values);
     }
     return $values;
 }
 /**
  *  @test
  */
 public function getValuesWhenQueryHasTwoSubgroupsSelectedAndTheReturnMustContainsOneListOfValuesToEachSubgroup()
 {
     $subgroup = $origin = $destiny = $font = 1;
     $variety = $type = array(1, 2);
     $dataParams = new DataParam($subgroup, $font, $type, $variety, $origin, $destiny);
     $this->repository->expects($this->at(0))->method('getValuesWithMultipleParamsSelected')->with($this->equalTo($dataParams), $this->equalTo(array(1, 2)))->will($this->returnValue($this->listFilteredByOneSubgroup()));
     $subgroup = 8;
     $origin = $destiny = $font = 1;
     $variety = $type = array(1, 2);
     $dataParams2 = new DataParam($subgroup, $font, $type, $variety, $origin, $destiny);
     $this->repository->expects($this->at(1))->method('getValuesWithMultipleParamsSelected')->with($this->equalTo($dataParams2), $this->equalTo(array(1, 2)))->will($this->returnValue($this->listFilteredByOtherSubgroup()));
     $subgroup = array(1, 8);
     $font = $origin = $destiny = 1;
     $variety = $type = array(1, 2);
     $dataParam = new DataParam($subgroup, $font, $type, $variety, $origin, $destiny);
     $values = $this->service->getValuesFilteringWithMultipleParams($dataParam, array(1, 2));
     $this->assertTrue($values instanceof HashMap);
     $this->assertEquals(1990, $values->get(0)->offsetGet(0)->getYear());
     $this->assertEquals('Brasil', $values->get(1)->offsetGet(0)->getOriginName());
     $this->assertEquals('USA', $values->get(1)->offsetGet(0)->getDestinyName());
     $this->assertEquals('Conilon', $values->get(1)->offsetGet(0)->getVariety());
     $this->assertEquals('Arábica', $values->get(0)->offsetGet(0)->getVariety());
 }