source

CLI에서 XDebug를 PHPUunit과 함께 실행하려면 어떻게 해야 합니까?

factcode 2023. 9. 1. 21:23
반응형

CLI에서 XDebug를 PHPUunit과 함께 실행하려면 어떻게 해야 합니까?

다음 CLI 명령을 실행해 보았습니다.

phpunit -d xdebug.profiler_enable=on XYZTestCase.php

정상적으로 작동합니다.누가 나에게 올바른 방향을 가르쳐 줄 수 있습니까?Thx!

XDebug 설정은 다음과 같습니다.

xdebug

xdebug support => enabled
Version => 2.1.2

Supported protocols => Revision
DBGp - Common DeBuGger Protocol => $Revision: 1.145 $

Directive => Local Value => Master Value
xdebug.auto_trace => Off => Off
xdebug.collect_assignments => Off => Off
xdebug.collect_includes => On => On
xdebug.collect_params => 0 => 0
xdebug.collect_return => Off => Off
xdebug.collect_vars => Off => Off
xdebug.default_enable => On => On
xdebug.dump.COOKIE => no value => no value
xdebug.dump.ENV => no value => no value
xdebug.dump.FILES => no value => no value
xdebug.dump.GET => no value => no value
xdebug.dump.POST => no value => no value
xdebug.dump.REQUEST => no value => no value
xdebug.dump.SERVER => no value => no value
xdebug.dump.SESSION => no value => no value
xdebug.dump_globals => On => On
xdebug.dump_once => On => On
xdebug.dump_undefined => Off => Off
xdebug.extended_info => On => On
xdebug.file_link_format => no value => no value
xdebug.idekey => Nam => no value
xdebug.manual_url => http://www.php.net => http://www.php.net
xdebug.max_nesting_level => 100 => 100
xdebug.overload_var_dump => On => On
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_output_dir => c:/wamp/tmp => c:/wamp/tmp
xdebug.profiler_output_name => cachegrind.out.%t.%p => cachegrind.out.%t.%p
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => Off => Off
xdebug.remote_cookie_expire_time => 3600 => 3600
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => localhost => localhost
xdebug.remote_log => no value => no value
xdebug.remote_mode => req => req
xdebug.remote_port => 9000 => 9000
xdebug.scream => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => \ => \
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => 128 => 128
xdebug.var_display_max_data => 512 => 512
xdebug.var_display_max_depth => 3 => 3

xdebug.profiler_enable설정은 실행 시에는 변경할 수 없지만 스크립트 시작 시에만 변경할 수 있습니다.

입니다.phpunit -d foo=bar단지 phpunit 호출로 이어질 것입니다.ini_set("foo", "bar");런타임에 값을 변경할 수 없기 때문에 작동하지 않습니다.

참조:

프로파일 출력 디렉터리에 파일을 만드는 Xdebug의 프로파일러를 활성화합니다.이러한 파일은 KCache Grind에서 읽어 데이터를 시각화할 수 있습니다.이 설정은 ini_set()로 스크립트에서 설정할 수 없습니다.프로파일러를 선택적으로 사용하려면 이 설정 대신 xdebug.profiler_enable_trigger를 1로 설정하십시오.

솔루션:

php -d xdebug.profiler_enable=on /usr/bin/phpunit XYZTestCase.php

이 설정을 PHP 단위가 아닌 PHP 런타임에 직접 적용하면 스크립트가 시작되기 전에 설정되며 작동해야 합니다.

이 일을 성공시키기 위해 오랜 시간을 보냈습니다.하지만 이것이 제 인생을 바꿀지도 모른다고 생각하세요!

저는 원래 부랑자 상자 안에서 이것을 하려고 했습니다(즉, phpunit 실행). 하지만 부랑자 상자 밖에서 실행하는 것이 더 쉽다는 것을 깨달았습니다(그리고 더 빠른 성능 현명함).

처음 사용한 것brew install php55 php55-xdebugMac에서 홈브루를 사용합니다(그러나 구성이 다를 수 있으며 계속 작동해야 함).제 사이트는 symphony2 프로젝트입니다.

저는 이것을 따르려고 했습니다: phpunit 부랑자 x 디버그는 부랑자 상자 안에서 작동하도록 했습니다(거의 도착했지만 몇 가지 문제가 있었습니다).

이러한 설정은 나에게 효과가 있었습니다(부랑자 상자에서 사이트를 실행하지만 부랑자 상자 외부에서 phpunit 실행).

#xdebug.ini (parent machine, not inside vagrant box).
[xdebug]
zend_extension="/usr/local/Cellar/php55-xdebug/2.2.6/xdebug.so" #this will be different on your machine and will probably already be set

xdebug.max_nesting_level = 250 
xdebug.default_enable = 1
xdebug.idekey = "PHPSTORM" #seems to work without this too
xdebug.remote_enable = 1

그런 다음 명령줄에서 이것을 실행합니다(여기서는 /usr/local/bin에 연결된 다운로드 대신 phpunit 다운로드를 사용하고 있습니다(작동하지 않는 것 같습니다).

XDEBUG_CONFIG="idekey=PHPSTORM" bin/phpunit -c app

또는 XDEBUG_CONFIG 환경 변수를 저장하기 위해 phpunit-debug라는 파일을 만들 수 있습니다. phpunit xdebug

다음을 시도해 보셨습니까?

  1. php.ini에서 xdebug.ide 키를 원하는 대로 설정합니다(예: blacktie).
  2. 서버 다시 시작

  3. -d xdebug.idekey=blacktie를 추가하여 스크립트 호출

    phpunit -dxdebug.profiler_enable=on -dxdebug.idekey=blacktie XYZTestCase.php

도움이 되길 바랍니다.

VS 코드 디버거(WSL 포함)를 사용하는 동안 터미널에서 해야 할 일은 다음 명령을 실행하는 것입니다.

export XDEBUG_CONFIG="idekey=VSCODE"

에 저는 합니다. 그 후 저 즉 phpunit 니 합 다 행 실 을phpunit ./tests/디버거는 제가 설정한 첫 번째 중단점에서 중지됩니다.

연결할 수 없는 코드에서 디버거가 일시 중지되는 경우 디버거 창의 중단점 아래에 있는 "모든 것"을 전환할 수 있습니다.

https://tighten.co/blog/configure-vscode-to-debug-phpunit-tests-with-xdebug 에서 이 정보를 얻었습니다.

편집 ::

위의 내용이 제 로컬 웹 서버에서 작동하는 동안.저는 오늘 제 프로젝트를 도커에 이식하려고 하다가 이것에 물렸습니다.

이 설정에서는 작동하지 않는 것으로 나타났습니다.

xdebug.remote_connect_back=1

대신 다음을 설정해야 합니다.

xdebug.remote_host=172.17.0.1
xdebug.remote_connect_back=0

참고: Linux에 있기 때문에 172.17.0.1을 사용하여 도커 컨테이너 내부에서 호스트 시스템을 참조하지만, Mac에 있는 경우에는 다음을 사용하는 것이 좋습니다.

xdebug.remote_host=docker.for.mac.host.internal
xdebug.remote_connect_back=0

또는 창에서:

xdebug.remote_host=host.docker.internal
xdebug.remote_connect_back=0

▁with다같.export XDEBUG_CONFIG="idekey=VSCODE"더 이상도 마찬가지야.

설정 은 올른설이름다같습다니음과은정바다▁the입니다.xdebug.profiler_enable합니다.명령을 다음으로 변경합니다.

phpunit -d xdebug.profiler_enable=on XYZTestCase.php

다음과 같은 환경 변수를 미리 설정하여 명령줄에서 Xdebug를 실행할 수 있습니다.

export XDEBUG_CONFIG="idekey=YOUR_IDE_KEY remote_host=localhost remote_enable=1"

이것은 저에게 효과가 있었습니다.

Xdebug 설명서에 대한 자세한 내용은 다음과 같습니다.

cookie/post/get 변수에 의해 트리거될 때 편집기/독립 실행형 디버거에서 이미 Xdebug가 작동하고 있다고 가정하면 동일한 트리거링을 수행하기 위해 셸 스크립트를 추가하면 기억할 내용이 줄어듭니다.

를 작성~/bin/php-cli-debug.sh:

#!/bin/bash
phpfile="$1"
idekey=YOUR_IDE_KEY
shift 1
php -d'xdebug.remote_enable=1' -d'xdebug.remote_autostart=1' -d'xdebug.idekey='"$idekey" -f "$phpfile" -- "$@"

그런 다음 CLI에서 디버깅하려면 다음과 같은 방법을 사용합니다.

$ php-cli-debug.sh "$(which phpunit)" --bootstrap tests/bootstrap.php tests/FooBarTest | less -S

다음 항목을 확인합니다..bashrc추가했습니다.~/bin의 신에게에.$PATH.

첫째, 환경:

  • WampServer 버전 3.1.3 64비트
  • Apache 2.4.33 - PHP 7.1.16
  • MySQL 5.7.21
  • MariaDB 10.2.14

php.ini:

[xdebug]
zend_extension ="c:/wamp64/bin/php/php7.1.16/zend_ext/php_xdebug-2.6.0-7.1-vc14-x86_64.dll"

xdebug.remote_enable = 1
xdebug.remote_autostart = 1
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir ="c:/wamp64/tmp"
xdebug.show_local_vars=0
xdebug.idekey = "PHPSTORM" #seems to work without this too

php 단위.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 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="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>
</phpunit>

나는 phpstorm에서 다음과 같은 테스트 실행 구성을 만들었습니다.

실행 구성 후 PHPSTORM에서 debug 버튼을 클릭하면 아래 명령어가 실행되었습니다.

C:\wamp64\bin\php\php7.1.16\php.exe
-dzend_extension=C:\wamp64\bin\php\php7.1.16\zend_ext\php_xdebug-2.6.0-7.1-vc14-x86_64.dll
-dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host=127.0.0.1 C:/wamp64/www/<PROJECT_FOLDER>/vendor/phpunit/phpunit/phpunit --bootstrap C:\wamp64\www\<PROJECT_FOLDER>\vendor\autoload.php --configuration C:\wamp64\www\<PROJECT_FOLDER>\phpunit.xml --teamcity

주목해주세요. 저는 전혀 모릅니다 :) 앞뒤 슬래시도 주목해주세요.

이것이 모두에게 도움이 되길 바랍니다.

phpStorm이 설치된 Windows의 경우

명령줄에 다음을 입력합니다.

set XDEBUG_CONFIG="idekey=PHPSTORM"

그러면 phpStorm이 찾는 환경 변수가 추가됩니다.

언급URL : https://stackoverflow.com/questions/12104303/how-can-i-get-xdebug-to-run-with-phpunit-on-the-cli

반응형