DevNetwork Forums

The Developer's Network
It is currently Mon Feb 08, 2010 10:16 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Error when using SimpleTest Mock::generate()
PostPosted: Thu Jun 01, 2006 9:43 am 
Offline
DevNet Master
User avatar

Joined: Tue Nov 02, 2004 6:43 am
Posts: 2704
Location: Ireland
Wondering if anyone has any idea what the following error is in relation to...

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):

[php]<?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');
}

}[/php]

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?

_________________
Pádraic Brady
Projects: PHPSpec, Zend Framework
Book: Zend Framework: Surviving The Deep End (Coming 2009)


Last edited by Maugrim_The_Reaper on Thu Jun 01, 2006 10:26 am, edited 1 time in total.

Top
 Profile E-mail  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 9:58 am 
Offline
Moderator
User avatar

Joined: Mon Nov 03, 2003 7:13 pm
Posts: 4679
Location: Odessa, Ukraine
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 10:20 am 
Offline
DevNet Master
User avatar

Joined: Tue Nov 02, 2004 6:43 am
Posts: 2704
Location: Ireland
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:

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).

_________________
Pádraic Brady
Projects: PHPSpec, Zend Framework
Book: Zend Framework: Surviving The Deep End (Coming 2009)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 12:30 pm 
Offline
Forum Contributor
User avatar

Joined: Wed Jun 29, 2005 10:04 pm
Posts: 276
Location: Iowa, USA
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?

_________________
Jason Sweat - ZCE
My Book: PHP Design Patterns
Good Stuff: SimpleTest WACT FireFox ADOdb JpSpan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 01, 2006 3:11 pm 
Offline
DevNet Master
User avatar

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

_________________
Pádraic Brady
Projects: PHPSpec, Zend Framework
Book: Zend Framework: Surviving The Deep End (Coming 2009)


Top
 Profile E-mail  
 
 Post subject: Mock Objects in Simple Test.
PostPosted: Sat Jul 01, 2006 10:45 pm 
Offline
Forum Newbie

Joined: Sat Jul 01, 2006 10:27 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 6:14 am 
Offline
Forum Commoner

Joined: Sat Jul 12, 2003 10:31 pm
Posts: 80
Location: London
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

_________________
Marcus Baker, http://www.lastcraft.com/
Unit test: Cgreen, SimpleTest, Fakemail


Top
 Profile E-mail  
 
 Post subject: Nice to see someone from lastcraft surfing the forums
PostPosted: Mon Jul 03, 2006 9:14 am 
Offline
Forum Newbie

Joined: Sat Jul 01, 2006 10:27 pm
Posts: 4
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.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 03, 2006 9:29 am 
Offline
DevNet Master
User avatar

Joined: Tue Nov 02, 2004 6:43 am
Posts: 2704
Location: Ireland
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.

_________________
Pádraic Brady
Projects: PHPSpec, Zend Framework
Book: Zend Framework: Surviving The Deep End (Coming 2009)


Top
 Profile E-mail  
 
 Post subject: Re: Nice to see someone from lastcraft surfing the forums
PostPosted: Wed Jul 05, 2006 6:24 pm 
Offline
Forum Commoner

Joined: Sat Jul 12, 2003 10:31 pm
Posts: 80
Location: London
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

_________________
Marcus Baker, http://www.lastcraft.com/
Unit test: Cgreen, SimpleTest, Fakemail


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


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 post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group