Message from discussion Unit Testing and NOW()
Received: by 10.231.8.219 with SMTP id i27mr48063ibi.24.1256500059829;
Sun, 25 Oct 2009 12:47:39 -0700 (PDT)
Received: by 10.231.8.219 with SMTP id i27mr48062ibi.24.1256500059685;
Sun, 25 Oct 2009 12:47:39 -0700 (PDT)
Received: from mail-iw0-f171.google.com (mail-iw0-f171.google.com [184.108.40.206])
by gmr-mx.google.com with ESMTP id 24si774565iwn.12.2009.10.25.12.47.38;
Sun, 25 Oct 2009 12:47:38 -0700 (PDT)
Received-SPF: pass (google.com: domain of trevor.mo...@gmail.com designates 220.127.116.11 as permitted sender) client-ip=18.104.22.168;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of trevor.mo...@gmail.com designates 22.214.171.124 as permitted sender) smtp.mail=trevor.mo...@gmail.com; dkim=pass (test mode) header...@gmail.com
Received: by iwn1 with SMTP id 1so5991073iwn.2
for <email@example.com>; Sun, 25 Oct 2009 12:47:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
DomainKey-Signature: a=rsa-sha1; c=nofws;
Received: by 10.231.28.143 with SMTP id m15mr3265429ibc.23.1256500058531; Sun,
25 Oct 2009 12:47:38 -0700 (PDT)
Date: Sun, 25 Oct 2009 16:47:38 -0300
Subject: Re: Unit Testing and NOW()
From: Trevor Morse <trevor.mo...@gmail.com>
To: Jonathan <jjmon...@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Thanks for the response! See my follow up below.
On Sun, Oct 25, 2009 at 11:49 AM, Jonathan <jjmon...@gmail.com> wrote:
> Yeah if dynamic data is what you're testing, I'd lose the XML file.
> But I think you should ask yourself why you would want to test MySQL's
> NOW() function. =A0You didn't write the code, and it's a pretty good bet
> the people at MySQL tested the function thoroughly. =A0All your code
> does is call the function. =A0If you had somehow written a stored
> procedure that extended the functionality of NOW(), I'd test that --
> it's your code, you should prove it works.
Well, what we are using is a function that actually creates the proper
database function based on the type of database(MySQL, Oracle, etc) we
are using. With hopes of becoming database independent in the future,
so there is some functionality I am testing there other then just
MySQL's NOW() function. :-)
> The only situation I see testing being useful is to make sure that
> you've populated the timestamp field at all, in which case you might
> test that the field is not NULL or whatever the default value.
What I actually ended up doing is sticking with the XML file for data
and using phpunit's db extensions filtering capability to ignore the
created and updated fields when using the db extension to compare. You
can get more info here -
I then figure out the current time, do a quick query to the database
and pull back the created/updated dates and make sure they happened in
the last 10 secs.
> On Jul 21, 11:51=A0am, Trevor Morse <trevor.mo...@gmail.com> wrote:
>> Hi Everyone,
>> I guess I'll be the one to break our question asking cherry. :-)
>> I don't know if any of you have used or are using phpunit for testing,
>> but here's my problem.
>> I am using phpunit and more specifically it's database extension to
>> test some code I am writing. This allows you to run some code, then
>> use an XML file to compare what's in the database with what should be
>> in the database. Which works great and is pretty cool, as long as you
>> do not have dynamic data.
>> Of course when you are updating rows in the table it is changing the
>> update date field and populating it using NOW(). So I can't find any
>> way to test this with the database extension.
>> I'm moving on to using regular unit test to validate the date/time
>> stamps but the only way I can think of to do that is to check for date/
>> time stamps in the last 30 seconds(or whatever interval is
>> reasonably). This seems kind of hokey though.
>> Any ideas/suggestions from anyone on a better approach?