Created
December 2, 2016 00:49
-
-
Save MarkBaker/7dd4bd939a0f3f4809970443fdc99cb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class evidenceController { | |
public function getDetails($id){ | |
$course = Course::with(['courseType']) | |
->checkEstablishmentOnView() | |
->excludeArchived() | |
->findOrFail($id); | |
$view = View::make('courses/parts/details') | |
->with('course', $course); | |
return Response::json(['html' => $view->render()]); | |
} | |
} |
hi @MarkBaker i interested in your code, i knew it just sample, but what is ->checkEstablishmentOnView()->excludeArchived()
? i usually use something like that just for accessor and mutator. can i see sample of that model to learn what you did with it?
@ysupr he is probably using Eloquent Scopes. Look it up in the documentation, it's quite handy :)
@taylorotwell you are only showing an example the first test you describe correct? Or am i misunderstanding. How do you go about testing the acual database call?
@ramirezd42 With integration tests instead of unit tests.
Returning a HTML blob in a JSON response?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You need to split this into two tests. Inject a repository into the controller with a single method that performs this query which you can easily Mock, then test the repository itself with an actual database call.