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)
Return-Path: <trevor.mo...@gmail.com>
Received: from mail-iw0-f171.google.com (mail-iw0-f171.google.com [209.85.223.171])
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 209.85.223.171 as permitted sender) client-ip=209.85.223.171;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of trevor.mo...@gmail.com designates 209.85.223.171 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 <halifax-ns-php-developers-group@googlegroups.com>; Sun, 25 Oct 2009 12:47:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=gamma;
h=domainkey-signature:mime-version:received:in-reply-to:references
:date:message-id:subject:from:to:cc:content-type
:content-transfer-encoding;
bh=syH1/u3CjcpNVeOG8MuoPCxVfvFfhFgGBdCPPibQSJY=;
b=kMSe02owartb0fNoTmZTrjEjq/rAI4DphVQlXq2x7Sg/luIpcYOO/KlCZgxQ5FGaPz
Q8APLYv/NGNNafMnZ0hbnUivTt3W5m+74U4w65crRlAKu7gJti+BCqTxr7RhS6a0UFsk
XoENsvRXiC3rv85fAy1MAKkIZfvMEOu38QKtw=
DomainKey-Signature: a=rsa-sha1; c=nofws;
d=gmail.com; s=gamma;
h=mime-version:in-reply-to:references:date:message-id:subject:from:to
:cc:content-type:content-transfer-encoding;
b=a9da8QZxPI+TgU6RMBxkjHBmk6WfDTpZBRi+UORr6UKWdqWOALxDX9Iylx5gTpBkx2
ZM24iESWQDOHyQFInvOpZx61PK5A5J9ZRDfn8utGal/qkY0uA7W2VRKpWsOTO1K1X3lQ
1Ps0A+i47Ji97UoRtGuUZ3doHWMJaPevAMy6k=
MIME-Version: 1.0
Received: by 10.231.28.143 with SMTP id m15mr3265429ibc.23.1256500058531; Sun,
25 Oct 2009 12:47:38 -0700 (PDT)
In-Reply-To: <d7a6e320-4854-4292-afbd-4f864a61e...@p23g2000vbl.googlegroups.com>
References: <02fb9421-956c-4927-a93c-4a1678f8b...@d4g2000yqa.googlegroups.com>
<d7a6e320-4854-4292-afbd-4f864a61e...@p23g2000vbl.googlegroups.com>
Date: Sun, 25 Oct 2009 16:47:38 -0300
Message-ID: <c36258b70910251247s443174e4vaac83640f07c8...@mail.gmail.com>
Subject: Re: Unit Testing and NOW()
From: Trevor Morse <trevor.mo...@gmail.com>
To: Jonathan <jjmon...@gmail.com>
Cc: halifax-ns-php-developers-group@googlegroups.com
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Hey Jonathan,
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.
>
> Reasonable?
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 -
http://www.digitalsandwich.com/archives/78-Improved-PHPUnit-Filters.html.
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.
Make sense?
Cheers,
Trevor
>
> 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?
>>
>> Thanks,
>>
>> Trevor