我一直在尝试使用PHPUnit代码覆盖率配置Laravel和Docker环境。我必须安装Xdebug,因为教程太多了,这很麻烦,其中大多数教程已经过时或无法正常工作。现在,当我尝试使用vendor/bin/phpunit
运行单元测试时,我终于安装了Xdebug,我得到了输出:
Declaration of Illuminate\Foundation\Auth\VerifiesEmails::show(Illuminate\Http\Request $request) should be compatible with App\Http\Controllers\Controller::show($id)"
我的单元测试不再运行。在this seems to be an issue updating PHP to 7.2周围搜索,这很奇怪,因为我的环境已经在php-7.2中建立。
我尝试运行composer update
并没有成功,但是对此问题一无所获。
PHP 7.2.19 Laravel版本5.8.26 PHPUnit版本7.5.13
我的Dockerfile:
FROM php:7.2-alpine as web
RUN apk add --no-cache \
openrc \
curl \
nodejs \
nodejs-npm \
npm
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl install xdebug-2.6.0beta1
RUN printf "xdebug.remote_enable=1\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.coverage_enable=1\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.idekey=\"PHPSTORM\"\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.remote_port=9000\n" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.remote_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN docker-php-ext-enable xdebug
RUN curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/bin/ --filename=composer
# An IDE key has to be set, but anything works, at least for PhpStorm and VS Code...
ENV XDEBUG_CONFIG="xdebug.idekey=''"
EXPOSE 80
更新:我的App \ Http \ Controllers \ Controller.php
use App\Services\Service;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
public function index(Request $request)
{
return response()->json([
'message' => __('messages.list'),
'data' => $this->service->all($request->all())
],200);
}
public function show($id)
{
return response()->json([
'message' => __('messages.list'),
'data' => $this->service->find($id)
], 200);
}
}
更新:问题和解决方法
我的Controller.php
由我的其他Controller(例如UserController,CaveController)继承,但也由Illuminate\Foundation\Auth\VerifiesEmailsController.php
继承,并且还具有方法show()
。为了解决这个问题,我从Controllers.php
中删除了Resource方法(例如,显示,索引和销毁),并创建了ResourceController.php
并继承了我的Resource方法中的Controller.php
。这样,我可以从show()
{。{1}}的{{1}}继承ResourceController.php
。