【问题标题】:PHPUnit Xdebug with PhpStorm Breakpoint is not being triggered unless I disable listening button除非我禁用监听按钮,否则不会触发带有 PhpStorm 断点的 PHPUnit Xdebug
【发布时间】:2018-05-15 21:23:20
【问题描述】:

我有一个非常奇怪的情况,PhpStorm 似乎没有捕获我的断点,除非我在启用监听按钮的情况下开始测试,然后在它启动后,然后禁用该按钮。

请参阅下面的屏幕截图和配置文件。

关于我可能配置不正确的任何想法?

这是 PhpStorm 在“挂起”时在控制台中显示的内容 -

Testing started at 12:57 PM ...
/usr/local/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9009 -dxdebug.remote_host=127.0.0.1 /private/var/folders/k7/ckk7n60x31s1h2s_hqcy9h4c0000gn/T/ide-phpunit.php --configuration /Users/justinwinter/Sites/drupal85/docroot/core/phpunit.xml --filter "/::testWatchdog( .*)?$/" Drupal\Tests\dblog\Functional\DbLogResourceTest /Users/justinwinter/Sites/drupal85/docroot/core/modules/dblog/tests/src/Functional/DbLogResourceTest.php
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Testing Drupal\Tests\dblog\Functional\DbLogResourceTest

这是一个截屏 gif,显示了仅在禁用 PhpStorm“停止侦听 PHP 调试连接”后才触发断点的奇怪行为

注意,根据这篇博文,我有一个本地 LAMP 堆栈设置并且运行良好: https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions

Xdebug 设置

xdebug
xdebug support => enabled
xdebug.auto_trace => Off => Off
xdebug.cli_color => 0 => 0
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.coverage_enable => On => On
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.force_display_errors => Off => Off
xdebug.force_error_reporting => 0 => 0
xdebug.halt_level => 0 => 0
xdebug.idekey => PHPSTORM => PHPSTORM
xdebug.max_nesting_level => 1000 => 1000
xdebug.max_stack_frames => -1 => -1
xdebug.overload_var_dump => 2 => 2
xdebug.profiler_aggregate => Off => Off
xdebug.profiler_append => Off => Off
xdebug.profiler_enable => Off => Off
xdebug.profiler_enable_trigger => Off => Off
xdebug.profiler_enable_trigger_value => no value => no value
xdebug.profiler_output_dir => /var/tmp/ => /var/tmp/
xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p
xdebug.remote_addr_header => no value => no value
xdebug.remote_autostart => On => On
xdebug.remote_connect_back => On => On
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 => /Users/justinwinter/Desktop/xdebug.log => /Users/justinwinter/Desktop/xdebug.log
xdebug.remote_mode => req => req
xdebug.remote_port => 9009 => 9009
xdebug.scream => Off => Off
xdebug.show_error_trace => Off => Off
xdebug.show_exception_trace => Off => Off
xdebug.show_local_vars => Off => Off
xdebug.show_mem_delta => Off => Off
xdebug.trace_enable_trigger => Off => Off
xdebug.trace_enable_trigger_value => no value => no value
xdebug.trace_format => 0 => 0
xdebug.trace_options => 0 => 0
xdebug.trace_output_dir => /var/tmp/ => /var/tmp/
xdebug.trace_output_name => trace.%c => trace.%c
xdebug.var_display_max_children => -1 => -1
xdebug.var_display_max_data => -1 => -1
xdebug.var_display_max_depth => -1 => -1

XDEBUG 日志 (GIST)

https://gist.github.com/anonymous/03a1e6bbf7139e2f860589f09ef1fa8e

这是我的 phpstorm 的另一个屏幕截图:语言和框架 > php > 测试框架屏幕


这是我用于 phpunit 配置文件的 core/phpunit.xml 文件。

<?xml version="1.0" encoding="UTF-8"?>

<!-- TODO set checkForUnintentionallyCoveredCode="true" once https://www.drupal.org/node/2626832 is resolved. -->
<!-- PHPUnit expects functional tests to be run with either a privileged user
 or your current system user. See core/tests/README.md and
 https://www.drupal.org/node/2116263 for details.
-->
<phpunit bootstrap="tests/bootstrap.php" colors="true"
         beStrictAboutTestsThatDoNotTestAnything="true"
         beStrictAboutOutputDuringTests="true"
         beStrictAboutChangesToGlobalState="true"
         checkForUnintentionallyCoveredCode="false">
<!-- TODO set printerClass="\Drupal\Tests\Listeners\HtmlOutputPrinter" once
 https://youtrack.jetbrains.com/issue/WI-24808 is resolved. Drupal provides a
 result printer that links to the html output results for functional tests.
 Unfortunately, this breaks the output of PHPStorm's PHPUnit runner. However, if
 using the command line you can add
 - -printer="\Drupal\Tests\Listeners\HtmlOutputPrinter" to use it (note there
 should be no spaces between the hyphens).
-->
  <php>
    <!-- Set error reporting to E_ALL. -->
    <ini name="error_reporting" value="32767"/>
    <!-- Do not limit the amount of memory tests take to run. -->
    <ini name="memory_limit" value="-1"/>
    <!-- Example SIMPLETEST_BASE_URL value: http://localhost -->
    <env name="SIMPLETEST_BASE_URL" value="http://drupal85.dev"/>
    <!-- Example SIMPLETEST_DB value: mysql://username:password@localhost/databasename#table_prefix -->
    <env name="SIMPLETEST_DB" value="mysql://root:@localhost/d8"/>
    <!-- Example BROWSERTEST_OUTPUT_DIRECTORY value: /path/to/webroot/sites/simpletest/browser_output -->
    <env name="BROWSERTEST_OUTPUT_DIRECTORY" value=""/>
    <!-- To disable deprecation testing uncomment the next line. -->
    <!-- <env name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/> -->
    <!-- Example for changing the driver args to mink tests MINK_DRIVER_ARGS value: '["http://127.0.0.1:8510"]' -->
    <!-- Example for changing the driver args to phantomjs tests MINK_DRIVER_ARGS_PHANTOMJS value: '["http://127.0.0.1:8510"]' -->
  </php>
  <testsuites>
    <testsuite name="unit">
      <file>./tests/TestSuites/UnitTestSuite.php</file>
    </testsuite>
    <testsuite name="kernel">
      <file>./tests/TestSuites/KernelTestSuite.php</file>
    </testsuite>
    <testsuite name="functional">
      <file>./tests/TestSuites/FunctionalTestSuite.php</file>
    </testsuite>
    <testsuite name="functional-javascript">
      <file>./tests/TestSuites/FunctionalJavascriptTestSuite.php</file>
    </testsuite>
  </testsuites>
  <listeners>
    <listener class="\Drupal\Tests\Listeners\DeprecationListener">
    </listener>
    <!-- The Symfony deprecation listener has to come after the Drupal
    deprecation listener -->
    <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
    </listener>
    <listener class="\Drupal\Tests\Listeners\DrupalStandardsListener">
    </listener>
    <listener class="\Drupal\Tests\Listeners\DrupalComponentTestListener">
    </listener>
  </listeners>
  <!-- Filter for coverage reports. -->
  <filter>
    <whitelist>
      <directory>./includes</directory>
      <directory>./lib</directory>
      <directory>./modules</directory>
      <directory>../modules</directory>
      <directory>../sites</directory>
      <!-- By definition test classes have no tests. -->
      <exclude>
        <directory suffix="Test.php">./</directory>
        <directory suffix="TestBase.php">./</directory>
      </exclude>
     </whitelist>
  </filter>
</phpunit>

PHPSTORM XDEBUG 设置


DBGp 代理设置 - 应该没关系吧?


更新:

根据@lazyone 提供的评论,我继续增加了同时连接的数量,并且能够让 PHPStorm 正确捕获断点。我不确定是否还有其他事情发生?

【问题讨论】:

  • 显示您的 PHPUnit 配置(以防万一)。但主要是——从 PhpStorm 设置中显示 Xdebug。理想情况下,最好在这里显示 xdebug 日志——看看它有什么要说的。不过,我有一个相当疯狂的猜测。附言不确定最后 3 个 env 变量(来自第 2/3 个屏幕截图) - 我认为它们不会以这种方式应用(端口和主机必须已经在实际的 php.ini 中正确写入;connect_back 选项似乎没有播放任何角色在这里(因为你的 xdebug 设置(最后一个列表)显示它是“开启”的)——但也许是因为它采取了不同的方式。
  • @LazyOne 我为我的 xdebug 日志添加了一个要点,并添加了我的 PHPStorm "Test Frameworks screen" 的另一个屏幕抓取。我还将添加我的phpunit.xml 文件。
  • 我已经要求 PhpStorm 提供 Xdebug 设置屏幕。 PHPUnit 配置没问题(没有找到可能有问题的选项)。
  • @LazyOne 对此感到抱歉 - 我想我已经附上了我在上面知道的唯一其他 XDebug 设置屏幕。最后两张截图。感谢您查看此内容!
  • 顺便说一句——我的“P.S.”表单第一条评论仍然存在——你通过这种方式的remote_connect_back没有任何区别(没有做你希望的事情)——xdebug清楚地表明xdebug仍然试图猜测IP,但因为它是一个CLI request 它显然没有找到任何 HTTP 标头,而是使用localhost)。不知道你在哪里通过这种方式传递配置会起作用(虽然没有检查你提供的链接,也许它在那里)

标签: php phpunit phpstorm xdebug drupal-8


【解决方案1】:

请在 PhpStorm 设置中增加 最大同时调试连接数 -- 默认情况下它只有 1 .. 并且基于 xdebug 日志(并且在再次检查质量很差的 gif 动画之后)你似乎有某种子请求正在进行......这需要单独的调试连接......IDE不能接受,因为它已经达到限制(1)。通过单击“停止侦听”,第一个连接被释放,因此 IDE 可以接受第二个。

很可能是因为测试代码的执行方式(例如 PHPUnit 设置,尽管我没有注意到 PHPUnit 配置文件中的这种情况下的预期选项)。

【讨论】:

    猜你喜欢
    • 2020-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-16
    • 2018-03-31
    • 2019-07-31
    • 1970-01-01
    相关资源
    最近更新 更多