Page 1 of 1

DBUnit is to JUnit as ??? is to PHPUnit

Posted: Tue Jun 12, 2007 3:10 pm
by loesak
I'm looking for a way to easily create (and teardown) data in a database from data definitions and integrate it in with my PHPUnit tests.
Is there any such thing out there for PHP that has this capability?

Thanks

Posted: Thu Jun 14, 2007 8:41 am
by loesak
OK, since i'm not getting any replies, i'll describe it more simply.

I want to define what data a particular user would have in the database.

Code: Select all

<user>
  <firstName>Bob</firstName>
  <lastName>Schmob</lastName>
  <birthDate>01/01/2000</birthdate>
  <account>
    <type>administrator</type>
    <createdDate>01/02/2001</createdDate>
  </account>
</user>
then i would like to have a PHP tool/framework that could parse this file, create the SQL and persist it to the database for me.
Kind of like many of the Java ORM's can do.

I desperatly do not want to make my own. So if anyone out there knows of a opensource free piece of software out there
PLEASE let me know. Thanks.

Posted: Thu Jun 14, 2007 8:52 am
by Luke
Have you heard of simpletest?

Posted: Thu Jun 14, 2007 9:58 am
by Maugrim_The_Reaper
What kind of testing are you performing? Generally speaking interacting with a database should never happen for Unit Tests. The only time it would be need is if the class being tested is a database abstraction layer (cannot be tested without a database - though even that's not always the case in PHP5) or when mock/stub objects cannot be written (can't think of an example in PHP, Java has far more examples).

It's unlikely you'll find anything concrete. I'd be inclined to contact the PHPUnit community directly and check if they're aware of something like this for PHP. Otherwise you'll have to DIY. Fact is, database libraries in PHP tend to be very easy to write stubs for. I'd say more than a few people have a stub generator sitting around for ADOdb and co.

Posted: Thu Jun 14, 2007 2:04 pm
by Weirdan
loesak wrote: then i would like to have a PHP tool/framework that could parse this file, create the SQL and persist it to the database for me.
Kind of like many of the Java ORM's can do.
I bet MDB2 could do that for you, as well as Propel.

Posted: Fri Jun 15, 2007 1:33 am
by dbevfat
Don't know about a standalone solution, but Symfony framework offsers this kind of functionality, maybe you can use some of it. See Populating a database at http://www.symfony-project.com/book/tru ... ment-Tools.

Posted: Fri Jun 22, 2007 11:57 am
by SprudelPaul
You're lucky, a couple of days ago PHPDBUnit was released, I think that's what you're looking for:
http://www.ds-o.com/archives/62-PHPDBUn ... PUnit.html

A very early release but better than nothing, I guess. :wink:

Posted: Sun Jun 24, 2007 11:02 pm
by ds
I wouldn't necessarily call it released. I hope to have the first beta out in next month. If there is anybody that would like to do some early testing and offer their feedback I would enjoy the help.