We help IT Professionals succeed at work.
Get Started

How do I run time-dependent database tests with PHPUnit?

tjgquicken asked
Last Modified: 2012-05-09
I have a PHP application and I want to test the functionality where it records each login attempt in the database, including the time of the login attempt. The SQL statement that I'm trying to test is "INSERT INTO logins VALUES {$email}, {$user_id}, NOW(), {$_SERVER['REMOTE_ADDR']}, {$login_successful}". The problem is, I can't figure out how to use PHPUnit to accomplish this. The issue is that PHPUnit seems to require that I write up my expected data set in an XML file and then compare that file to what's in the database --- but since the value of NOW() depends on when I'm running the test, I can't have a pre-written file to compare against. Has anybody else run into this issue, and what's the best way to work around it? Thanks.
Watch Question
Top Expert 2007
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE