NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Debugging issues of PHPUnit tests in PhpED


Joined: 17 Jan 2011
Posts: 22
Reply with quote
PhpED has issues when debugging (not running) some type of tests with PHPUnit.
For example mock of a class with multiple methods.

Code:
class MyClass
{
    function root($x)
    {
        $base = $this->getRootBase();
        $presision = $this->getConfig('presision');
        $root = pow($x, 1/$base);
        return round($root, $presision);
    }
   
    protected function getConfig($key)
    {
        $aConfig['presision'] = 2;
        return $aConfig[$key];
    }
   
    protected function getRootBase()
    {
        return 3;
    }
}


We need a mock of MyClass with two methods:
Code:
class MyClassTest extends PHPUnit_Framework_TestCase
{
    function testroot()
    {
        $mockMy = $this->getMock('\MyClass', array('getConfig', 'getRootBase'));
       
        $mockMy->expects($this->any())
            ->method('getConfig')
            ->with('presision')
            ->will($this->returnValue(2));
           
        $mockMy->expects($this->any())
            ->method('getRootBase')
            ->will($this->returnValue(2));
       
        $this->assertEquals(2.83, $mockMy->root(8));
    }
}


When I try to debug a such test in PhpED I get an error message:
Project ... raised exception class PHPUnit_Framework_ComparisionFailure with message: "Failed asserting that strings are equal."
This happens only while debugging. Running such tests has no problem in PhpED.
View user's profileFind all posts by mikhailtSend private message


Joined: 30 Jun 2009
Posts: 80
Reply with quote
That's because PHPEd handles all exceptions thrown during a debug session.

You can filter those messages by the exception's namespace in project's debugging properties.
View user's profileFind all posts by temuriSend private message


Joined: 17 Jan 2011
Posts: 22
Reply with quote
That's right that PhpED handles exceptions. But there should not be any exceptions in this code.
It is totally legal code.
Something goes wrong only while debugging when comparing mock-methods names when there are more then one method. And that should not be.
View user's profileFind all posts by mikhailtSend private message


Joined: 30 Jun 2009
Posts: 80
Reply with quote
I don't think that's the case.

Nothing goes wrong when debugging session is enabled. It's only alerting you to an exception that otherwise would have been caught.

What happens if you catch the exception and click "Break" button and continue in the debugger? My bet is that you will find yourself in catch () {....} block.
View user's profileFind all posts by temuriSend private message
Debugging issues of PHPUnit tests in PhpED
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic