Comparte:
Test Guzzle
Hola! tengo un problema con el test:
Es el consumo de una api con autenticación. No tengo problemas en obtener los datos el problema es en el test
que me da error.
Clase que consume cliente guzzle:
que me da error.
Clase que consume cliente guzzle:
namespace App\Repositories;
use GuzzleHttp\Client;
class Communes
{
public function get()
{
$client = new Client([
'base_uri' => 'https://api.shipit.cl/v/',
]);
$headers = [
'Content-Type' => 'application/json' ,
'X-Shipit-Email' => 'prueba_front@shipit.cl',
'X-Shipit-Access-Token' => 'MWhEAdkHKYdscen_4cxR',
'Accept' => 'application/vnd.shipit.v2',
];
$reponse = $client->request('GET', 'communes',[
'headers' => $headers
]);
return json_decode($reponse->getBody()->getContents());
}
}
Controlador:
namespace App\Http\Controllers;
use App\Repositories\Communes;
class CommunesController extends Controller
{
protected $communes;
public function __construct(Communes $communes){
$this->communes = $communes;
}
public function index(){
$comunas = $this->communes->get();
return view('welcome',compact('comunas'));
}
}
test:
/**
* @test
*/
public function shipit_communes(){
$this->withHeaders([
'Content-Type' => 'application/json' ,
'X-Shipit-Email' => 'prueba_front@shipit.cl',
'X-Shipit-Access-Token' => 'MWhEAdkHKYdscen_4cxR',
'Accept' => 'application/vnd.shipit.v2',
])->json('GET', 'https://api.shipit.cl/v/communes')
->assertStatus(200);
}
error:
Expected status code 200 but received 404.
Failed asserting that false is true.
Failed asserting that false is true.
salu2