03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Controller Testing 369<br />

20 $requestMock<br />

21 ->shouldReceive("get")<br />

22 ->atLeast()<br />

23 ->once()<br />

24 ->with("title");<br />

25<br />

26 $requestMock<br />

27 ->shouldReceive("get")<br />

28 ->atLeast()<br />

29 ->once()<br />

30 ->with("subtitle");<br />

31<br />

32 $requestMock<br />

33 ->shouldReceive("get")<br />

34 ->atLeast()<br />

35 ->once()<br />

36 ->with("body");<br />

37<br />

38 $requestMock<br />

39 ->shouldReceive("get")<br />

40 ->atLeast()<br />

41 ->once()<br />

42 ->with("author");<br />

43<br />

44 $postRepository = new PostRepository($requestMock);<br />

45 $postRepository->insert();<br />

46 }<br />

47<br />

48 protected function getRequestMock()<br />

49 {<br />

50 return Mockery::mock("Illuminate\Http\Request");<br />

51 }<br />

52 }<br />

.<br />

This file should be saved as app/tests/Formativ/PostRepositoryTest.php.<br />

All we’re doing here is making sure the get method is called four times, on the request dependency.<br />

We could extend this to accommodate requests against the underlying database connector object,<br />

and the test code would be similar.<br />

We can’t completely test the Str::slug() method because it’s not a facade but water a static method on

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!