【发布时间】:2019-03-31 19:02:06
【问题描述】:
我这样写测试
$response = $this->actingAs(\App\Models\User::first())
->post(route('profile-menu.update', $profile), [
'image' => UploadedFile::fake()->image('avatar.jpg', 900, 500)->size(100),
'profile' => [
'en' => [
'title' => 'test',
'description' => 'test'
],
'id' => [
'title' => 'test',
'description' => 'test'
]
]
]);
print_r($response->decodeResponseJson());
$response->assertStatus(302);
然后我在我的控制器顶部导入需求
namespace App\Http\Controllers\Admin;
use File;
use Image;
use Storage;
我已经注册了干预服务提供者并为其写了别名。
测试结果是
1) Tests\Feature\MyTest::testUpdateProfileDetail
Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Image::make()
/opt/atlassian/pipelines/agent/build/app/Http/Controllers/Admin/ProfileMenuController.php:72
我无法弄清楚 phpunit 无法识别 Image::make() 的原因,是我的脚本有问题还是它来自流水线服务的错误?
【问题讨论】:
-
使用 Intervention\Image\Facades\Image;包括它
-
我已经在配置中将其设为别名,它应该可以正常工作吗?如果我在测试环境/我的本地计算机之外执行它,它可以工作,但是它抛出 500 错误说 Image::make() 是未定义的。我认为环境有问题
标签: laravel phpunit pipelining