我是laravel的新手,我可以成功运行我的文件上传器,它成功上传我的文件,但单元测试失败,这是我的代码:
UploadTest.php
public function testUploadFile()
{
$fileSize = 1024; // 1mb
$fileName = 'file.txt';
Storage::fake('files');
$response = $this->json('POST', '/webservice/upload', [
'file' => UploadedFile::fake()->create($fileName, $fileSize)
]);
Storage::disk('files')->assertExists($fileName);
Storage::disk('files')->assertMissing($fileName);
}
Run Code Online (Sandbox Code Playgroud)
FileUploadController
public function upload(Request $request)
{
$file = $request->file('file');
if ($file == null) {
return view('fileupload',
['submitClickedMsg' => "Please select a file to upload."]);
}
$path = $file->storeAs('files', $file->getClientOriginalName(), 'local');
return response()->json([
'path' => $path
]);
}
Run Code Online (Sandbox Code Playgroud)
filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' …Run Code Online (Sandbox Code Playgroud) 我正在尝试 PHP 编码标准包:https://github.com/inpsyde/php-coding-standards,但是当我开始运行 phpcs 时,我得到:
nickan@nickan-VirtualBox:~/src/wordpress/wp-content/plugins/my-plugin$ vendor/bin/phpcs ./src/model/Users.php
E 1 / 1 (100%)
FILE: /home/src/wordpress/wp-content/plugins/my-plugin/src/model/Users.php
-------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------
5 | ERROR | Class 'Plugin\Model\Users', located at
| | '/home/src/wordpress/wp-content/plugins/my-plugin/src/model/Users.php', is not
| | compliant with PSR-4 configuration. (Inpsyde.CodeQuality.Psr4.InvalidPSR4)
Run Code Online (Sandbox Code Playgroud)
这是路径中的文件my-plugin/src/model/Users.php
<?php declare(strict_types=1);
namespace Test\Model;
class Users
{
}
Run Code Online (Sandbox Code Playgroud)
我不明白出了什么问题,代码工作正常,但错误不断出现。我尝试使用不同的命名空间、更改文件夹等,但仍然无济于事,将不胜感激。谢谢。