【发布时间】:2020-06-29 00:15:44
【问题描述】:
当我运行测试时,我得到了下一个错误:
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
Warning: Invocation with class name is deprecated
ErrorException : Undefined variable: status
/opt/project/vendor/laravel/lumen-framework/src/Testing/Concerns/MakesHttpRequests.php:424
这是我的代码:
<?php
use Laravel\Lumen\Testing\DatabaseTransactions;
class AuthControllerTest extends TestCase
{
use DatabaseTransactions;
public function testLogin()
{
$params = ['email' => 'super@mail.com', 'password' => '12345678'];
$response = $this->post('/web/auth/login', $params);
$response->assertResponseStatus(200);
$response->seeJsonStructure(['data', 'message']);
}
}
phpunit.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory suffix="Test.php">./tests</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="QUEUE_CONNECTION" value="sync"/>
</php>
</phpunit>
作曲家文件
...
"require": {
"php": "^7.2.5",
"barryvdh/laravel-dompdf": "^0.8",
"guzzlehttp/guzzle": "^6.5",
"illuminate/mail": "7.1.1",
"illuminate/redis": "^7.1",
"laravel-doctrine/orm": "1.6",
"laravel/lumen-framework": "^7.0",
"lcobucci/jwt": "^3.2",
"palanik/lumen-cors": "dev-master",
"phpmailer/phpmailer": "^6.1.4",
"predis/predis": "^1.1"
},
"require-dev": {
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "^3.1"
},
...
PHP 版本 7.2.21
我正在使用 docker 在容器中测试我的代码,我不知道后者是否相关。 也就是调试的响应,呈现的是status的值,所以不明白PHPUnit为什么会抛出错误。
感谢您的支持。
【问题讨论】: