29.07.2016 Views

laravel-5

Create successful ePaper yourself

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

Testing 356<br />

.<br />

1 public function testPhotoCanBeUploaded()<br />

2 {<br />

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

4 ->name('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 />

.<br />

1

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

Saved successfully!

Ooh no, something went wrong!