小编Nic*_*kan的帖子

Laravel 5.6测试文件上传(无法在路径[file.txt]中找到文件)

我是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 phpunit ubuntu-16.04 laravel-5.6

6
推荐指数
1
解决办法
2489
查看次数

错误:类“路径”不符合 PSR-4 配置

我正在尝试 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)

我不明白出了什么问题,代码工作正常,但错误不断出现。我尝试使用不同的命名空间、更改文件夹等,但仍然无济于事,将不胜感激。谢谢。

psr-4 phpcs

2
推荐指数
1
解决办法
453
查看次数

标签 统计

laravel-5.6 ×1

php ×1

phpcs ×1

phpunit ×1

psr-4 ×1

ubuntu-16.04 ×1