xdebug、phpunit和vim。上下文中的“未初始化”变量

4
我正在使用vim插件https://github.com/ludovicPelle/vim-xdebug和xdebug,与常规脚本相比,Xdebug和vim插件的使用没有问题。我可以逐步执行并打印变量。但是,在尝试逐步执行基本单元测试时,它可以顺利地到达断点并停止,我可以顺利地逐步执行代码,但无法再查看变量内容。 我正在尝试将其与一个非常基本的单元测试配合使用。
class testClass extends \PHPUnit_Framework_TestCase
{
  public function testSomething()
  { 
    $a = 5;
    $b = 6;
    $c = 7;
  } 
}

当我在方法的结尾处尝试打印出$a的内容时,我会得到以下错误提示。
13 : send =====> property_get -i 13 -d 0 -n a
13 : recv <===== {{{   <?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="property_get" transaction_id="13" status="break" reason="ok"><error code="300"><message><![CDATA[can not get property]]></message></error></response>
}}}
response status=break xmlns=urn:debugger_protocol_v1 xmlns:xdebug=http://xdebug.org/dbgp/xdebug reason=ok command=property_get transaction_id=13
error code=300 : Can not get property (when the requested property to get did not exist, this is NOT used for an existing but uninitialized property, which just gets the type "uninitialised" (See: PreferredTypeNames)).
    message
        can not get property

当我打印整个上下文时,这3个变量显示如下:
$command = 'context_get';
 a                    = /* uninitialized */'';
 b                    = /* uninitialized */'';
 c                    = /* uninitialized */'';

我知道phpunit在运行测试类的方法时会有一些有趣的技巧,这可能是为什么调试器没有返回方法中的变量的原因。如果有任何建议,将不胜感激,谢谢。


错误信息指的是一个属性,但在您的代码中我只看到了局部变量。因此,无论您试图做什么,结果都会检查testClass::$a,而不是$a - Fabian Schmengler
2个回答

0

你需要做类似这样的事情

class testClass extends \PHPUnit_Framework_TestCase
{
    $a = 0;
    $b = 0;
    $c = 0;

  function dosomething() {
    $a = 5;
    $b = 6;
    $c = 7;
  }
}

或者你需要包含一个变量文件

你的 var.php 文件

<?

  $a = 0;
  $b = 0;
  $c = 0;

?>


0
问题最终是由我使用的xdebug版本引起的,显然这是2.0中已知的问题,在2.1中得到了修复。我正在调试的虚拟机是ubuntu 10.04 LTS。
在这个Ubuntu版本发布时,xdebug 2.1仍然是一个发行候选版。我编译了最新版本的xdebug,现在能够查看方法内的变量。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接