Program Club

Laravel 5 : PHPUnit 및 사용 가능한 코드 커버리지 드라이버 없음

proclub 2020. 12. 25. 00:10
반응형

Laravel 5 : PHPUnit 및 사용 가능한 코드 커버리지 드라이버 없음


PHPUnit을 사용하여 코드 커버리지 보고서를 만들고 싶습니다. 웹에서 찾은 많은 설치 설정을 시도했습니다. 그러나 아무것도 해결되지 않는 것 같습니다.

최신 버전의 Laravel 5 (> 5.2)와 PHPUnit v. 5.0.10을 사용합니다. 또한 PHP 7을 실행하는 Mac OS X 10.9.5에서 MAMP를 사용합니다.

Laravel 배포판에 통합 된 PHPUnit을 실행하면 다음과 같은 오류가 발생합니다.

$ vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml
Error:         No code coverage driver is available`

내 작곡가 파일은 다음과 같습니다.

"require-dev": {
    "fzaninotto/faker": "~1.4",
    "mockery/mockery": "0.9.*",
    "phpunit/phpunit": "5.0.*",
    "phpunit/php-code-coverage": "^3",
    "symfony/css-selector": "2.8.*|3.0.*",
    "symfony/dom-crawler": "2.8.*|3.0.*"
},

또한 다음 명령을 시도했습니다.

/Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v

이것은 코드 커버리지 드라이버를 잘 설정하는 것처럼 보이지만 예외로 끝납니다.

$ /Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.

Runtime:       PHPDBG 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml

[PHP Fatal error:  Uncaught ErrorException: include(/Applications/MAMP/htdocs/myProject/app/Exceptions/Handler.php): failed to open stream: Too many open files in /Applications/MAMP/htdocs/myProject/vendor/composer/ClassLoader.php:412
Stack trace:
...

phpunit.xml은 다음과 같습니다.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
     backupStaticAttributes="false"
     bootstrap="bootstrap/autoload.php"
     colors="true"
     convertErrorsToExceptions="true"
     convertNoticesToExceptions="true"
     convertWarningsToExceptions="true"
     processIsolation="false"
     stopOnFailure="false">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./tests/</directory>
        </testsuite>
    </testsuites>
    <logging>
      <log type="coverage-html" target="./tests/codeCoverage" charset="UTF-8"/>
    </logging>
    <filter>
        <whitelist>
            <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"/>
    </php>
</phpunit>

라 라벨 프레임 워크와 함께 제공되는 PHPUnit을 코드 커버리지와 함께 사용할 수 있습니까? 어떻게 설정하고 사용해야합니까?

도와 주셔서 정말로 고맙습니다.


It seems like you are missing the Xdebug extension. If you're using homebrew you can install it like:

brew install php70-xdebug

After that, don't forget to edit your php.ini file to enable the extension.

php -i | grep xdebug

After checking that xdebug is enabled you should be able to do code coverage


Update for anyone else stuck;

pecl install xdebug


Update for PHP 7.1

xdebug is essential for code lookup and coverage , so xdebug is must to be installed or enabled in test environment. xdebug in production environment is not suggestible, it will affect performance if you turned on

brew install php71-xdebug


If you run phpunit inside a vagrant box then you don't need to install xdebug in local and homestead comes with xdebug install automatically. only needs to link homestead xdebug.ini file

Here is the step that worked for me:

cd ~/homestead/REPLACE THIS WITH YOUR HOMESTEAD FOLDER IN LOCAL //
vagrant ssh

sudo ln -s /etc/php/7.2/fpm/conf.d/20-xdebug.ini /etc/php/7.2/cli/conf.d/

In the above command if your running 7.3 or 7.1 then replace it based on your php version


For windows users:

1) Download xdebug

2) Rename the file to _php_xdebug.dll_ and copy the file to the ext folder in your php installation e.g C:\Program Files (x86)\php\ext

3) Open your php.ini file. For me it’s available at C:\Program Files (x86)\php\php.ini.

4) Paste the below code at the bottom of the file.

zend_extension = php_xdebug.dll
xdebug.remote_enable = 1
xdebug.remote_handler = dbgp
xdebug.remote_host = localhost
xdebug.remote_autostart = 1
xdebug.remote_port = 9000
xdebug.show_local_vars = 1

As other developers answered, you need to install PHP Xdebug but I want to add new recommend for the developers who are using homestead by default have Xdebug (but it is off) and you can make it ON or OFF

If you want to make it on use below command in homestead

#for on :
xon

#for off:
xoff

Then check php -v and you will see Xdebug in the detail box

ReferenceURL : https://stackoverflow.com/questions/35811503/laravel-5-phpunit-and-no-code-coverage-driver-available

반응형