I've been trying to configure my Laravel and Docker environment with PHPUnit code coverage. I had to install Xdebug which was a pain in the ass with so many different tutorials and most of them outdated or not working. Now that I finally installed Xdebug when I try to run my unit tests with vendor/bin/phpunit
I'm getting the output:
Declaration of Illuminate\Foundation\Auth\VerifiesEmails::show(Illuminate\Http\Request $request) should be compatible with App\Http\Controllers\Controller::show($id)"
And my unit tests are not running anymore. Searching around this seems to be an issue updating PHP to 7.2 which is weird because my env was built already in php-7.2.
I've tried running composer update
with no success and found nothing about this issue.
PHP 7.2.19 Laravel version 5.8.26 PHPUnit version 7.5.13
my 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
" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.coverage_enable=1
" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.idekey=\"PHPSTORM\"
" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
"xdebug.remote_port=9000
" >> /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
update: my 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);
}
}
Update: Problem and Fix
My Controller.php
is inherited by my other Controllers(e.g. UserController, CaveController) but it is also inherited by Illuminate\Foundation\Auth\VerifiesEmailsController.php
and it also have a method show()
. To fix I removed my Resource methods from Controllers.php
(e.g. show, index and destroy) and created ResourceController.php
inheriting Controller.php
with my resource methods. With this i can inherit show()
from ResourceController.php
in my UserController
, CaveController
.....