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);
开发者_Python百科//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
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.
If your machine has some space then you could put your objects into the $_SESSION. But beware, Doctrine objects can grow pretty large.
精彩评论