使用存储的测试方法失败。 Illuminate\Http\Testing\imagepng() 在 Laravel
Test methods fail using Storage. Illuminate\Http\Testing\imagepng() in Laravel
你好,我正在做TDD来测试我的开发,我的测试一直在通过,直到我决定重新安装php修复sqlite
驱动进行测试(主要驱动是mysql
).因此,当我 运行 我的漏洞测试套件时,此错误显示在使用 storage
:
的每个方法中
Error : Call to undefined function Illuminate\Http\Testing\imagepng()
{laravel}/framework/src/Illuminate/Http/Testing/FileFactory.php:46
{laravel}/framework/src/Illuminate/Support/helpers.php:1038
{laravel}/framework/src/Illuminate/Http/Testing/FileFactory.php:49
{laravel}/framework/src/Illuminate/Http/Testing/FileFactory.php:31
{laravel}/tests/Feature/FacilityTest.php:38
这是一种抛出上述错误的方法(第 38
行已发出信号):
/**
* @test
* Test for: a Facility can be registered by an admin.
*/
public function a_facility_can_be_registered_by_an_admin()
{
/** Given a correct information for a facility */
\Storage::fake('public');
// Next line is line 38, the problematic one:
$data = ["name" => "AAA", 'image' => UploadedFile::fake()->image('aaa.jpg')];
/** When the request is made by an admin */
$admin = $this->createUser([], 'admin');
$response = $this->apiAs($admin, 'POST', '/api/v1/manage/facilities', $data);
/** Then the facility should be registered */
$response->assertStatus(Response::HTTP_CREATED);
}
真不知道为什么。
如果有帮助,这是我的php单元文件:
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
</php>
</phpunit>
无论执行什么测试,都需要有 PHP GD 扩展名
我最近 运行 遇到了这个问题并安装了 PHP GD Extension
这是我放在 Dockerfile
中的代码
RUN apt-get update && \
apt-get install -y \
libzip-dev \
libjpeg62-turbo-dev \
libpng-dev
RUN docker-php-ext-install gd
Note: Installing gd requires that you have libzip, libpng e.t.c
你好,我正在做TDD来测试我的开发,我的测试一直在通过,直到我决定重新安装php修复sqlite
驱动进行测试(主要驱动是mysql
).因此,当我 运行 我的漏洞测试套件时,此错误显示在使用 storage
:
Error : Call to undefined function Illuminate\Http\Testing\imagepng() {laravel}/framework/src/Illuminate/Http/Testing/FileFactory.php:46 {laravel}/framework/src/Illuminate/Support/helpers.php:1038 {laravel}/framework/src/Illuminate/Http/Testing/FileFactory.php:49 {laravel}/framework/src/Illuminate/Http/Testing/FileFactory.php:31 {laravel}/tests/Feature/FacilityTest.php:38
这是一种抛出上述错误的方法(第 38
行已发出信号):
/**
* @test
* Test for: a Facility can be registered by an admin.
*/
public function a_facility_can_be_registered_by_an_admin()
{
/** Given a correct information for a facility */
\Storage::fake('public');
// Next line is line 38, the problematic one:
$data = ["name" => "AAA", 'image' => UploadedFile::fake()->image('aaa.jpg')];
/** When the request is made by an admin */
$admin = $this->createUser([], 'admin');
$response = $this->apiAs($admin, 'POST', '/api/v1/manage/facilities', $data);
/** Then the facility should be registered */
$response->assertStatus(Response::HTTP_CREATED);
}
真不知道为什么。
如果有帮助,这是我的php单元文件:
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="DB_CONNECTION" value="sqlite"/>
</php>
</phpunit>
无论执行什么测试,都需要有 PHP GD 扩展名
我最近 运行 遇到了这个问题并安装了 PHP GD Extension
这是我放在 Dockerfile
RUN apt-get update && \
apt-get install -y \
libzip-dev \
libjpeg62-turbo-dev \
libpng-dev
RUN docker-php-ext-install gd
Note: Installing gd requires that you have libzip, libpng e.t.c