MightMock EntitySave

13 views
Skip to first unread message

Andrew Scott

unread,
Sep 27, 2009, 5:29:02 AM9/27/09
to mxu...@googlegroups.com

 

I am trying to use injectMethod to overwrite a call to entitySave to mock the database call, which doesn’t work.

 

Is there a more preferred or better way?

 

bill shelton

unread,
Sep 27, 2009, 7:35:54 AM9/27/09
to mxunit
Hi Andrew,

Could you post a small code snippet and maybe a stack trace?

MightyMock is /still/ pre-alpha, but help your situation. Bob
Silverberg and others have been particularly helpful shaping it. I
hope to roll it into MXUnit before year's end. Anyone interested in
helping to grow MightyMock please drop me a note!

bill

Andrew Scott

unread,
Sep 27, 2009, 7:48:16 AM9/27/09
to mxu...@googlegroups.com
From what I can tell it is the problem of ColdFusion 9, I can't give a stack
trace because there is no error.

For example I have code like this

remote orm.mango.blog function createBlog(blog item) {
entitySave(item);
ormFlush();
return item;
}

In my unitTest I have this

<cfset injectMethod(obj, this, "entitySave_Replacement",
"saveEntity") />
<cfset blog.setid('100') />
<cfset ret = obj.createBlog(blog) />
<cfset assertEquals(ret.getid(), '100') />

The problem is that entitySave is not overridden here, and the ORM
entitySave is still called. I have also posted this in the prerelease forums
as well. To see if Adobe would consider allowing us to override these
methods/functions.
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 8.5.409 / Virus Database: 270.13.113/2397 - Release Date: 09/26/09
17:51:00

Marc Esher

unread,
Sep 27, 2009, 7:50:02 AM9/27/09
to mxu...@googlegroups.com, <mxunit@googlegroups.com>
Injectmethod is for overwriting your own functions, not builtin
functions like entitysave

Sent from my iPhone

On Sep 27, 2009, at 5:29 AM, "Andrew Scott" <and...@andyscott.id.au>
wrote:

bill shelton

unread,
Sep 27, 2009, 7:56:13 AM9/27/09
to mxunit
Got it. You probably want to wrap entitySave in it's own method and
then mock that; e.g.,

remote orm.mango.blog function createBlog(blog item) {
myLocalEntitySave(item);
ormFlush();
return item;

}

...

<cfset injectMethod(obj, this, "entitySave_Replacement",
"myLocalEntitySave") />


bill

On Sep 27, 7:50 am, Marc Esher <marc.es...@gmail.com> wrote:
> Injectmethod is for overwriting your own functions, not builtin  
> functions like entitysave
>
> Sent from my iPhone
>
> On Sep 27, 2009, at 5:29 AM, "Andrew Scott" <andr...@andyscott.id.au>  

Andrew Scott

unread,
Sep 27, 2009, 8:30:42 AM9/27/09
to mxu...@googlegroups.com
Yeah that's what I ended up doing, created an abstractComponent for all the
entity functions. A lot of work that seems weird to do because Adobe want
allow us to over ride these things.

The other thing I tried to do was add a private method called entitySave()
in the component, that will never get called either. It won't error but it
won't call the method just call the builtin function.

-----Original Message-----
From: mxu...@googlegroups.com [mailto:mxu...@googlegroups.com] On Behalf Of
bill shelton
Sent: Sunday, 27 September 2009 9:56 PM
To: mxunit

Sean Corfield

unread,
Sep 27, 2009, 2:02:30 PM9/27/09
to mxu...@googlegroups.com
On Sun, Sep 27, 2009 at 5:30 AM, Andrew Scott <and...@andyscott.id.au> wrote:
> The other thing I tried to do was add a private method called entitySave()
> in the component, that will never get called either. It won't error but it
> won't call the method just call the builtin function.

You'd need to call variables.entitySave() to pick up the local method,
as I understand Adobe's implementation (which would never call the
built-in).

But you could, theoretically, have:

private function entitySave(item) {
entitySave(item);
}

and that would be the 'same' as your myLocalEntitySave() method but a
bit neater. Maybe.
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies US -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Reply all
Reply to author
Forward
0 new messages