Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jarektkaczyk/055eefc4da2949c517c140160bc50919 to your computer and use it in GitHub Desktop.
Save jarektkaczyk/055eefc4da2949c517c140160bc50919 to your computer and use it in GitHub Desktop.
// controller
$course = Course::with(...)->checkEstablishmentOnView()->excludeArchived()->findOrFail($id);
$view = View::make('some.view')->with('course', $course);
return response()->json(['html' => $view->render()]);
// kahlan spec
it('does some magic and unicorns and all that stuff', function () {
allow(Double::classname(['class' => App\Course::class]))->toReceive('::with')->andReturn($query = Double::instance());
allow($query)->toReceive('checkEstablishmentOnView->excludeArchived->findOrFail')->andReturn('your model here');
allow(Double::classname(['class' => 'View']))->toReceive('::make')->with('some/partial/view')->andReturn($view = Double::instance());
allow($view)->toReceive('with')->andReturn($view);
allow($view)->toReceive('render')->andReturn('view contents');
$this->laravel->get('testing/1')->seeJsonContains(['html' => 'view contents'])->assertResponseOk();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment