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

How To play 25MB+ audio file directly from google drive in HTML 5?
PHP/MYSQL - Select option value not being sent?
Laravel : How to use a parameters in a Form POST to be use in a Route::post?
How to convert object format to json format in php
laravel,how i can change the code to return an array?
How to make At Least Two Field Required to fill in Laravel 5.2
How do I allow PHP to run when the script is not in the URL?
How to check if a file is BEING used, i.e. some command is being executed on the data in that file?
Display profile data from database when login
How to integrate laravel packages into an application
Log into a Django project using Magento user database SSO
Image not show in recyclerview from server
php table exporting it to excel [duplicate]
regex not closing span
How to use GroupBy in nested query in Laravel 5?
Laravel Users table Update

Categories

HOME
apache-nifi
verification
vagrant
ios-simulator
portable-class-library
video-streaming
stored-procedures
cisco
anchor
hspi
eddystone
bellman-ford
clickable-image
spring-security-oauth2
twitter-oauth
alljoyn
bundler
bnf
phonegap-build
mixpanel
pickle
dashdb
kaggle
liferay-6.2
sap-lumira
gravity-forms-plugin
tortoisehg
vcenter
apptentive
landscape
elastica
data-uri
icepdf
distributed-caching
hypothesis-test
coverage.py
git-tfs
adblock
ol3-google-maps
entropy
msxml
emf-compare
ogg
pjax
jsonix
clp
gcloud-node
mathml
fiber
qpixmap
maximize
distributed-cache
ioctl
textpattern
miniconda
chicagoboss
fanotify
netdatacontractserializer
web-api
scala-swing
nssortdescriptor
signed
findersync
juttle
flurry-analytics
device-admin
window-resize
quantify
ecos
git-reset
screwturn
wso2bam
jomsocial
strcmp
jmenubar
quickgraph
icenium
onconfigurationchanged
clearinterval
gamesalad
opends
n-queens
glx
litespeed
glassfish-esb
fragment-identifier
photo-management
servlet-container
dip
resharper-5.1
external-sorting
isapi-redirect
downloadfile

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App