Error when using SimpleTest Mock::generate()

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

Error when using SimpleTest Mock::generate()

Postby Maugrim_The_Reaper » Thu Jun 01, 2006 9:43 am

Wondering if anyone has any idea what the following error is in relation to...

Syntax: [ Download ] [ Hide ]
Fail: /opt/lampp/htdocs/quantumstar/trunk/Tests/Partholan/Test_DataObject.php -> Bad GroupTest [/opt/lampp/htdocs/quantumstar/trunk/Tests/Partholan/Test_DataObject.php] with error [Non-static method Mock::generate() should not be called statically, assuming $this from incompatible context]


Relevant parts (only started writing the test so not sure if that is a possible cause):

Syntax: [ Download ] [ Hide ]
<?php



// Simple Test files included earlier: unit_tester.php, mock_objects.php, reporter.php

require_once(APPROOT . 'Partholan/Abstracts/Parth_DataObject.php');

require_once(APPROOT . 'Partholan/Classes/Parth_DataAccess.php');

require_once(TESTROOT . 'Other/Item.php'); // simple Parth_DataObject child for testing



Mock::generate('Parth_DataAccess');



class Test_DataObject extends UnitTestCase {



        private $item1;

        private $item2;



        public function __construct() {

                $this->UnitTestCase('Test of DataObject');

                // return values for future mocked DataAccess classes

                $this->item1 = new Item(array('item_id'=>1,'item_name'=>'Test Item','item_text'=>'Test Item 001'), new MockParth_DataAccess());

                $this->item2 = new Item(array('item_id'=>2,'item_name'=>'Test Item','item_text'=>'Test Item 002'), new MockParth_DataAccess());

        }



        public function setUp() {

        }



        public function tearDown() {

        }



        public function testGetByPk() {

                $dao = new MockParth_DataAccess();

                $do = new Item(array(), $dao);

                $dao->expectOnce('getByPk', array($do, 1));

                $dao->setReturnValue('getByPk', $this->item1);

                $do->getByPk(1);

                // DAO overwrites $do reference

                $this->assertIsA($do, 'Parth_DataObject');

                $this->assertEqual($do->getItemId(), 1);

                $this->assertEqual($do->getItemName(), 'Test Item');

                $this->assertEqual($do->getItemText(), 'Test Item 001');

        }



}


This could be a PHP error (not caused by test) but I ran several other test suites using Mocks under the same environment (using PHP 5.1.4) and no similar error occured. This test, like the others which ran without error, had error_reporting() set to E_ALL.

Anyone have any ideas?
Last edited by Maugrim_The_Reaper on Thu Jun 01, 2006 10:26 am, edited 1 time in total.
User avatar
Maugrim_The_Reaper
DevNet Master
 
Posts: 2702
Joined: Tue Nov 02, 2004 6:43 am
Location: Ireland

Postby Weirdan » Thu Jun 01, 2006 9:58 am

you may try to search the SimpleTest sources for the line where the error is thrown...
this could give you ideas on what made the Mock::generate method think it shouldn't be called statically...
Image
User avatar
Weirdan
Moderator
 
Posts: 5068
Joined: Mon Nov 03, 2003 7:13 pm
Location: Odessa, Ukraine

Postby Maugrim_The_Reaper » Thu Jun 01, 2006 10:20 am

Was trying that.

I altered the function declaration to "static function generate...". That got rid of the error, but the Mocked object does not appear to have been generated:

Syntax: [ Download ] [ Hide ]
Fatal error: Class 'MockParth_DataAccess' not found in /opt/lampp/htdocs/quantumstar/trunk/Tests/Partholan/Test_DataObject.php on line 17


Get the same error when I try to impose a Mock classname manually.

I must be missing something - it seems to work for other tests (completely different app) for the same SimpleTest version (copied it across as a test).
User avatar
Maugrim_The_Reaper
DevNet Master
 
Posts: 2702
Joined: Tue Nov 02, 2004 6:43 am
Location: Ireland

Postby sweatje » Thu Jun 01, 2006 12:30 pm

That seems like it might be related to the elevated E_STRICT notices with the recent PHP releases (starting 5.1.3 I think)

Can you ensure the E_STRICT error level is not set when running your test?
User avatar
sweatje
Forum Contributor
 
Posts: 276
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Postby Maugrim_The_Reaper » Thu Jun 01, 2006 3:11 pm

error_reporting is set to E_ALL. I'll see if disabling it completely works...
User avatar
Maugrim_The_Reaper
DevNet Master
 
Posts: 2702
Joined: Tue Nov 02, 2004 6:43 am
Location: Ireland

Mock Objects in Simple Test.

Postby Gaspard » Sat Jul 01, 2006 10:45 pm

I've had the same problem with Mock Objects in SimpleTest. Has anyone found a solution to this? Turning the errors downs down a notch just doesn't seem like the best solution. Especially since the group I'm working in is all fairly new to PHP.

Also, where is SimpleTest 1.0. At SourceForge there is a SimpleTest Eclipse Plug-in in beta, and SimpleTest 1.bar-alpha. Currently we are using the SimpleTest Eclispse Plug-in to run tests inside web pages, but as you can imagine this doens't seem like the best setup.

Gaspard Out.
Gaspard
Forum Newbie
 
Posts: 4
Joined: Sat Jul 01, 2006 10:27 pm

Postby lastcraft » Mon Jul 03, 2006 6:14 am

Hi...

Could you try an experiment for me? Could you move the mock instantiation out of the constructor and into the setUp() method to see if that makes any difference. This is just a hunch.

Also, is there any executing code in the data object file? That is, code that is not inside a function or class? I am just wondering if either of these could cause problems.

Regarding E_STRICT, I cannot maintain PHP4 compatibility and at the same time make the code E_STRICT clean. It's just not possible. After SimpleTest 1.0.1, I'll be switching to PHP5.1+ only. I don't have the resources to maintain two versions, so I want to get the PHP4 version bug free before I abandon it.

yours, Marcus
lastcraft
Forum Commoner
 
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London

Nice to see someone from lastcraft surfing the forums

Postby Gaspard » Mon Jul 03, 2006 9:14 am

Hey Marcus,

I'll try that out, and yes I was trying to instantiate the mock_object outside of setup.

If we gave you some examples of simpletests that you could just copy and paste, or download to get running, rather than having a an imaginary log.php file, would you be willing to post it on your site.

Gaspard Out.
Gaspard
Forum Newbie
 
Posts: 4
Joined: Sat Jul 01, 2006 10:27 pm

Postby Maugrim_The_Reaper » Mon Jul 03, 2006 9:29 am

At the moment the static keyword suppresses the error (of course this is under PHP5). I'll take a look later on if I have time and try what you suggested. The problem with Mock objects not being created has "gone away" on my setup. I was playing around with adding the first Mock static call to the inside of an if(true) statement but I don't see what difference that would possibly make. Since it does work with another set of tests I just copied what was done there, and it magically worked.

I left it alone at that point :).

I'll grab my May 31 revision from subversion and give it another look.
User avatar
Maugrim_The_Reaper
DevNet Master
 
Posts: 2702
Joined: Tue Nov 02, 2004 6:43 am
Location: Ireland

Re: Nice to see someone from lastcraft surfing the forums

Postby lastcraft » Wed Jul 05, 2006 6:24 pm

Hi...

Gaspard wrote:If we gave you some examples of simpletests that you could just copy and paste, or download to get running, rather than having a an imaginary log.php file, would you be willing to post it on your site.


Of course. The only problem is that I am backed up on site updates and was planning a complete overhaul of the tutorials anyway. SimpleTest has had to make way for paid work and pregnancy, but I'm back on the case now. I'll check back in when I have made some progress.

yours, Marcus
lastcraft
Forum Commoner
 
Posts: 80
Joined: Sat Jul 12, 2003 10:31 pm
Location: London


Return to Testing

Who is online

Users browsing this forum: No registered users and 1 guest