06.10.2016 Views

laravel-5

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

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

Testing 468<br />

Working With Attachments<br />

If your form contains file input types, you may attach files to the form using the attach method:<br />

1 public function testPhotoCanBeUploaded()<br />

2 {<br />

3 $this->visit('/upload')<br />

4 ->type('File Name', 'name')<br />

5 ->attach($absolutePathToFile, 'photo')<br />

6 ->press('Upload')<br />

7 ->see('Upload Successful!');<br />

8 }<br />

Testing JSON APIs<br />

Laravel also provides several helpers for testing JSON APIs and their responses. For example, the<br />

get, post, put, patch, and delete methods may be used to issue requests with various HTTP verbs.<br />

You may also easily pass data and headers to these methods. To get started, let’s write a test to make<br />

a POST request to /user and assert that a given array was returned in JSON format:<br />

1

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

Saved successfully!

Ooh no, something went wrong!