Skip to content

Commit a4c0022

Browse files
Add test for file uploads
1 parent c41d587 commit a4c0022

File tree

5 files changed

+20
-0
lines changed

5 files changed

+20
-0
lines changed

app/Http/Controllers/HomeController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,15 @@ public function serviceContainer()
148148
{
149149
return view('service-container');
150150
}
151+
152+
/**
153+
* @param \Illuminate\Http\Request $request
154+
* @return string
155+
*/
156+
public function upload(Request $request)
157+
{
158+
$uploadedFile = $request->file('file');
159+
160+
return $uploadedFile->isValid() ? 'Success' : 'Failure';
161+
}
151162
}

app/Http/routes.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
Route::get('fire-event', 'HomeController@fireEvent');
2727
Route::get('validation', 'HomeController@validation');
2828
Route::get('service-container', 'HomeController@serviceContainer');
29+
Route::post('upload', 'HomeController@upload');
2930
Route::match(['get', 'post'], 'form', 'HomeController@form');
3031

3132
Route::resource('posts', 'PostsController');

tests/_data/logo.jpg

8.42 KB
Loading

tests/functional.suite.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ modules:
33
enabled:
44
- Helper\Functional
55
- Asserts
6+
- REST:
7+
depends: Laravel5
68
- Laravel5:
79
environment_file: .env.testing
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
$I = new FunctionalTester($scenario);
3+
$I->wantTo('upload a file');
4+
$I->amOnPage(''); // Necessary to prevent LogicException with message "The page history is empty".
5+
$I->sendPOST('upload', [], ['file' => codecept_data_dir('logo.jpg')]);
6+
$I->see('Success');

0 commit comments

Comments
 (0)