简体   繁体   中英

xdebug, phpunit, and vim. 'uninitialized' variables in context

I am using this vim plugin https://github.com/ludovicPelle/vim-xdebug with xdebug

Xdebug and the vim plugin are working fine with regular scripts. I can step through and print out variables.

When I try to step through a basic unit test, it gets to the breakpoint fine and stops, and I can step through the code ok, but I can no longer view the contents of variables.

I am trying to get this to work with a very basic unit test

class testClass extends \PHPUnit_Framework_TestCase
{
  public function testSomething()
  { 
    $a = 5;
    $b = 6;
    $c = 7;
  } 
}

When I step to the end of the method and try to print out the contents of $a, I get the following error.

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

When I print out the whole context the 3 variables show up as follows

$command = 'context_get';
 a                    = /* uninitialized */'';
 b                    = /* uninitialized */'';
 c                    = /* uninitialized */'';

I know that phpunit does some interesting tricks when it runs the methods of a test class, so that might be why the debugger isn't returning the variables in the method. Any suggestions would be greatly appreciated, thanks.

You need to do something like this

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

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

Or you need to include a variable file

your var.php file

<?

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

?>

The problem turned out to be the version of xdebug I was using, apparently this is a known issue in 2.0 which was fixed in 2.1 The virtual machine I am debugging on is ubuntu 10.04 LTS

At the time that this version of Ubuntu was released xdebug 2.1 was still a release candidate. I compiled the most recent version of xdebug and I am able to view the variables within a method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM