views:

25

answers:

2

Hi, within my Unit-tests i would like to have the following behavior:

$myNewDoctrineRecord = new Dto_MyRecord();
$myNewDoctrineRecord->pk = 1; //the primary key
...
$myNewDoctrineRecord->save();

Now this record shouldnt really persist to the database. But i would like to do

$myFetchedDoctrineRecord = Doctrine::getTable('Dto_MyRecord')->find(1);
//result should be $myFetchedDoctrineRecord === $myNewDoctrineRecord

I know this could be achived with a DAO pattern, where i replace the DAO to some mock. But maybe there is some possibility so just say Doctrine not to persist, but only to "remember" the records.

Thank you! Markus

+1  A: 

You could start a transaction, and at the end of the test rollback. That way you can still find() the records created within the transaction, but the rollback will ensure they're not persisted.

reko_t
yea, good idea! but my problem is performance. I really would like to not access the database at all.
Markus
Well the only other way is to create a mock object, I don't think Doctrine offers any other way. Another alternative would be to use something like SQLite memory database for the tests, because accessing it is _very_ fast.
reko_t
A: 

If your machine has some space then you could put your objects into the $_SESSION. But beware, Doctrine objects can grow pretty large.

ITroubs