03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Controller Testing 364<br />

.<br />

This file should be saved as phpunit.xml.<br />

This will get the tests running, and serves as a template in which to start writing our tests. You can<br />

actually see this test case working, by running the following command:<br />

1 phpunit<br />

2<br />

3 PHPUnit 4.0.14 by Sebastian Bergmann.<br />

4<br />

5 Configuration read from /path/to/phpunit.xml<br />

6<br />

7 .<br />

8<br />

9 Time: 76 ms, Memory: 8.75Mb<br />

10<br />

11 OK (1 test, 0 assertions)<br />

.<br />

This test is functional because it only happens after a Laravel instance is spun up, and it doesn’t<br />

care about what state it leaves this application instance in.<br />

Since we haven’t implemented the body of the send() method, it’s difficult for us to know what<br />

the return value will be. What we can test for is what methods (on the mailer’s underlying mail<br />

transport/interface) are being called…<br />

Imagine we’re using the underlying Laravel mail class to send the emails. We used it before we<br />

started optimising the controller layer:<br />

1 Mail::send("emails.post", Input::all(), function($email) {<br />

2 $email<br />

3 ->to("cgpitt@gmail.com", "Chris")<br />

4 ->subject("New post");<br />

5 });

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

Saved successfully!

Ooh no, something went wrong!