igaster's avatar
Level 11

How do you Test Package routes?

Hello!

I am building a package and I want to define some routes in order to provide an HTTP API to the application.

I develop the package on isolation (ie not inside a Laravel application) and I am using orchestral/testbench to build my Tests.

Question:

  1. How do I test my routes (for example hit a route url, get the response and run my assertions) since there is no application domain?

  2. Maybe I could setup Homestead to provide a domain. (?) But what about Travis or other CI services? Can my tests be executed on a remote service?

0 likes
2 replies
igaster's avatar
Level 11

After some searching I reached into the following solution:

$request = Request::create('/api/endpoind', 'GET');
$response = \App::handle($request); // Evaluate request & execute controller acions
// $response is the actual return value from your controller. eg a Illuminate\Http\Response
$response->getContent(); // To string
json_decode($response->getContent()); // to JSON etc...
jpsoft45's avatar

Hi @igaster That is not work when i write that code in test case of custome package of laravel give me error like Route not found

Please or to participate in this conversation.