コード例 #1
0
 public function testGetMarcas()
 {
     $tabelas = FipeGratis::getTabelas(FipeGratis::CARRO);
     $codigoTabela = $tabelas[0]['codigo'];
     $marcas = FipeGratis::getMarcas(FipeGratis::CARRO, $codigoTabela);
     $codigoMarca = $marcas[0]['codigo'];
     $modelos = FipeGratis::getModelos(FipeGratis::CARRO, $codigoTabela, $codigoMarca);
     $codigoModelo = $modelos[0]['codigo'];
     $anos = FipeGratis::getAnos(FipeGratis::CARRO, $codigoTabela, $codigoMarca, $codigoModelo);
     $codigoAno = $anos[0]['codigo'];
     $precoMedio = FipeGratis::getPrecoMedio(FipeGratis::CARRO, $codigoTabela, $codigoMarca, $codigoModelo, $codigoAno);
     $this->assertEquals(count($tabelas) > 0, true);
     $this->assertEquals(count($marcas) > 0, true);
     $this->assertEquals(count($modelos) > 0, true);
     $this->assertEquals(count($anos) > 0, true);
     $this->assertEquals(is_float($precoMedio), true);
 }
コード例 #2
0
 /**
  * Metodo para capturar os PARAM's
  *
  * @param  string $tipo
  * @throws Exception
  * @return void
  */
 private static function setParams($tipo = null)
 {
     FipeGratis::setCookie($tipo);
     $ch = curl_init("http://www.fipe.org.br/web/indices/veiculos/default.aspx?azxp=1&{$tipo}");
     $options = array(CURLOPT_COOKIEJAR => 'cookiejar', CURLOPT_HTTPHEADER => array("User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0", "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.5,en;q=0.3", "Accept-Encoding: gzip, deflate", "Referer: http://www.fipe.org.br/web/index.asp?{$tipo}&aspx=/web/indices/veiculos/default.aspx", "Cookie: " . FipeGratis::$__COOKIE . "", "Connection: keep-alive"), CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => 1);
     curl_setopt_array($ch, $options);
     $html = curl_exec($ch);
     curl_close($ch);
     $crawler = new Crawler($html);
     FipeGratis::$__PARAM_EVENTARGUMENT = $crawler->filter('#__EVENTARGUMENT')->attr('value');
     FipeGratis::$__PARAM_EVENTVALIDATION = $crawler->filter('#__EVENTVALIDATION')->attr('value');
     FipeGratis::$__PARAM_VIEWSTATE = $crawler->filter('#__VIEWSTATE')->attr('value');
     FipeGratis::$__PARAM_VIEWSTATEGENERATOR = $crawler->filter('#__VIEWSTATEGENERATOR')->attr('value');
 }