Page 1 of 1

[SOLVED] SimpleTest error

Posted: Tue Feb 20, 2007 9:30 am
by Jenk
I'm receiving an error after I generate a mock object; and I'm not sure what is causing it. Is this a common problem?

Code: Select all

Fatal error: Call to a member function tell() on a non-object in C:\www\simpletest\mock_objects.php on line 413

Code: Select all

require_once('../simpletest/unit_tester.php');
require_once('../simpletest/mock_objects.php');
require_once('../simpletest/reporter.php');
require_once('../lib/Jenk/Controller/Router.php');

class Jenk_Controller_Router_Route
{
    public function getController ()
    {
    }

    public function getAction ()
    {
    }

    public function isMatch ()
    {
    }
}

class Jenk_Controller_Dispatcher
{
    public function execute()
    {
    }
}

Mock::generate('Jenk_Controller_Router_Route', 'MockRoute');
Mock::generate('Jenk_Controller_Dispatcher', 'MockDispatch');

class RouterTest extends UnitTestCase
{
    private $_router;
    private $_dispatcher;
    private $_mockRoute;
    
    public function __construct ()
    {
        parent::__construct();
        $this->_router = new Jenk_Controller_Router();
        $this->_mockRoute = new MockRoute(); // if I comment out this line, the error ceases - but my test fails of course.
    }

Posted: Tue Feb 20, 2007 10:23 am
by Chris Corbyn
Try this:

Code: Select all

$this->_mockRoute = new MockRoute($this);

Posted: Tue Feb 20, 2007 10:32 am
by Maugrim_The_Reaper
Try adding a constructor to the class being mocked? I rarely if ever have a class without a constructor so not a clue as to whether this impacts anything really ;). But only thing I noted as odd from my perspective.

Posted: Tue Feb 20, 2007 10:36 am
by Jenk
No change I'm afraid, both with MockRoute($this) and a constructor in the class.

Puzzling. I searched google for 'simpletest "call to a member function tell"' and got one result in French, but I recognised that they were blaming it on PHP's regression (or lack of.)

I'm not sure I know what that means, but would that be a cause?

Posted: Tue Feb 20, 2007 11:35 am
by Maugrim_The_Reaper
It's a weird line error - tell() is called on the current test case as fetched from the current Context. It should be working unless the test has not been setup correctly (something bad enough that simpletest can't find it, or isn't aware of it.).

What SimpleTest version are you using? I can check it later against my own copy and the current Beta. If it's a very old SimpleTest version, and you're using PHP 5.2+ it could easily be a simpletest problem. It had a few early PHP5.2 bugs, and I haven't tested myself on 5.2.1.

Posted: Tue Feb 20, 2007 12:31 pm
by Jenk
about to try again now that I am at home, it was with the latest simpletest version at work but I can't remember which PHP version I've got installed on work machine.

Posted: Wed Feb 21, 2007 5:16 am
by Jenk
Never got round to trying it at home, but I've now reinstalled with the latest and greatest of everything at work, but still the same error.

Done some digging and it is because the TestCase is never set within SimpleTest class - will continue debugging when I get some more time.

Posted: Wed Feb 21, 2007 6:11 am
by Jenk
Resolved..

instead of declaring within the TestCase constructor, it (they) must be decalred within the test method:

Code: Select all

Mock::generate(/* snip.. */);
class Test extends UnitTestCase
{
    private $_mockRoute;

    public function __construct ()
    {
        //this fails..
        $this->_mockRoute = new MockRoute($this);
    }

    public function TestSomething ()
    {
        //this doesn't..
        $this->_mockRoute = new MockRoute($this);
    }
}