php


Laravel: Undefined method fake on Laravel storage facades for file upload testing


I am starting to learn TDD by experimenting in Laravel's HTTP test. Here's my test function:
public function testLoginUsingUserDeni() {
$response = $this->json('POST', '/api/v1/login', [
'email' => 'ramadhanrperdana#gmail.com',
'password' => 'secret'
]);
$response
->assertStatus(200)
->assertJSONStructure($this->loginSuccessJsonStructure);
return $response->original['token'];
}
/**
* #depends testLoginUsingUserDeni
*/
public function testGambarBaru($token) {
Storage::fake('gambar');
$response = $this->json('POST', '/api/gambar/baru', [
'token' => $token,
'gambar' => UploadedFile::fake()->image('evidence.jpg'),
'posisi' => 1
]);
Storage::disk('gambar')->assertExists('evidence.jpg');
$response
->assertStatus(200)
->assertJSONStructure($this->gambarJsonStructure);
}
But, after running the test I got error like this:
PHPUnit 5.7.11 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.13-0ubuntu0.16.04.1
Configuration: /home/kromatin/Projects/PJB REMBANG/web-apps/KawistaK3_web/phpunit.xml
..E....................................... 42 / 42 (100%)
Time: 2.94 seconds, Memory: 20.00MB
There was 1 error:
1) Tests\Feature\Api\GambarTest::testGambarBaru
BadMethodCallException: Call to undefined method League\Flysystem\Filesystem::fake
/home/kromatin/Projects/PJB REMBANG/web-apps/KawistaK3_web/vendor/league/flysystem/src/Plugin/PluggableTrait.php:86
/home/kromatin/Projects/PJB REMBANG/web-apps/KawistaK3_web/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemAdapter.php:475
/home/kromatin/Projects/PJB REMBANG/web-apps/KawistaK3_web/vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php:328
/home/kromatin/Projects/PJB REMBANG/web-apps/KawistaK3_web/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:221
/home/kromatin/Projects/PJB REMBANG/web-apps/KawistaK3_web/tests/Feature/Api/GambarTest.php:65
ERRORS!
Tests: 42, Assertions: 313, Errors: 1.
Script phpunit --color=always --verbose handling the test event returned with error code 2
I got error when executing testGambarBaru function, while other functions worked well. That error pointed to the line where I place Storage::fake('gambar');.
The purpose of my test function is to ensure my file upload API works well. I followed Laravel's documentation about testing file upload from this doc: https://laravel.com/docs/5.4/http-tests#testing-file-uploads. But the result said there is no method called fake in Storage Facade. I've done some search inside vendor directory to find any fake method around Storage facades but I can't find it. I am using Laravel 5.4. Is there something I've missed?
[SOLVED]
I checked laravel's Github repository and realized that fake method for Storage Facade added several days ago. After doing composer update my problem solved.
Lesson learned today was to not neglecting such a powerfull tool like composer and make sure to update our project dependencies to ensure that we can execute latest feature as well.

Related Links

Is PHP compiled or interpreted?
preg_replace with php code
PHP $_SERVER['REMOTE_HOST'] returns ::1 [duplicate]
unset the array
How to best handle exception to repeating calendar events
How to get the path of a file before its uploaded?
How to implement a Bloom Filter in PHP?
How to resize YouTube player when Window Resize
Tags/Documentation with SVN Project in Eclipse?
Problem on how to display members info from a database with mysql and php? [duplicate]
PHP MySQL Backup script on IIS Server
Simple testimonial rotator
How did PHP 5.3 break your application? [closed]
simplexml + foreach +twitter with unexpected results
PHP/MySQL Timezone Clarification
Open Source PHP Form Management System?

Categories

HOME
elasticsearch
visual-studio
shinyapps
focus
livecode
exchange-server
devexpress
haproxy
biztalk-2010
gentelella
turbojpeg
bittorrent
repair
siesta
migrate
fbloginview
circleci
grocery-crud
smartgwt
trace32
xbox360
nullreferenceexception
angular2-highcharts
multi-upload
intel
ini
password-generator
multi-dimensional-scaling
background-color
jackrabbit-oak
mongodb-3.4
john-the-ripper
twilio-php
ms-dos
unification
extbase
flowchart
utf
opal-framework
word-cloud
expandablelistview
gcal
sonicmq
phppgadmin
popen
email-forwarding
hmmlearn
pbx
gapi
boost-compute
openquery
carmen
spring-mongo
codecharge
apple-configurator
urbit
swiffy
gulp-uglify
as3-api
openmrs
phpquery
knife
mobilefirst-server
alwayson
relational-model
artisan
kefir.js
wicked-gem
r.java-file
phonegap-facebook-plugin
juttle
utf8-decode
multivariate-testing
relationships
squeezebox
windows-messages
sql-function
pageviews
map
proxy-server
spring-security-acl
eclim
sly-scroller
arel
semicolon
xalan
cgrectmake
story
wndproc
first-class
dynamic-c
filelock
anonymous-types
pyjamas
android-2.1-eclair
tessellation
spring-modules
.net-client-profile
accumulator
iphone-sdk-3.1.3
account-management

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App