Symfony-style InMemory Repository for TYPO3.Flow

By | 20/04/2014

logo_symfony_headerTYPO3-FLOW Some time ago I worked on a Symfony Project at the office where we used a Webservice to fetch all the required data. We used Repositories, that call the web service and return the data. For our set of functional tests we used inMemory Repositories to get some data back from the application, without calling the web service. Basically the InMemory repositories just returned the objects that the web service would return, but without calling the web service. So for testing some frontend stuff, the testing context automatically injected the inMemory repositories into our controllers.

Since Symfony and Flow are not that fare away from each other, I was just wondering if it is possible to do the same thing in Flow. The big difference is, that Flow automatically wires the model to the repository and therefor there where two big differences.

First of all, I used the Objects.yaml to tell Flow in dependency of the context, which repository it should use. The second thing was to tell the repository where his model is. It is one thing, writing two repositories for two different things, but I did not want to write to identically models.

So fore the Testing context the Object.yaml looks like following:

For the Development context the Object.yaml looks like:

Good thing is, that you can tell the repositories in Flow to which models they belong by setting the constant ENTITY_CLASSNAME.

So in both repositories I set:

Finally the result of everything can be found here:

https://github.com/tlayh/Layh.Testing

If you call the package via the browser, you can add the Something Object to the database, while the functional tests access the InMemory repository and return a different set of data.

Normally you would use a Testdatabase for such a case, but in the Symfony project we did, there was no database at all, so we where really happy about the InMemory repositories.

Disclaimer:

This code might be not perfect, but I am open for feedback. Basically this was just a proof of concept if it is possible or not.