[SOLVED] SimpleTest error

Discussion of testing theory and practice, including methodologies (such as TDD, BDD, DDD, Agile, XP) and software - anything to do with testing goes here. (Formerly "The Testing Side of Development")

Moderator: General Moderators

Post Reply
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

[SOLVED] SimpleTest error

Post 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.
    }
Last edited by Jenk on Wed Feb 21, 2007 6:15 am, edited 1 time in total.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Try this:

Code: Select all

$this->_mockRoute = new MockRoute($this);
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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?
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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);
    }
}
Post Reply