I am just trying to write some integration tests to tackle a certain issue on an app. In fact, one of the migrations caused trouble as some assumptions on the table content were wrong.
Here come some general information, the main questions are at the ending.
In order to test this properly, the idea was to use integration/installation tests based on PHPUnit. (This is, in general, a good idea as I think to test as much as possible.) What is existing/working:
- A fixture is generated that allows to reset the complete database and files to a vanilla state (NC installed with app enabled).
PHPUnit\Framework\TestCaseis created to run the tests with various cases
setUp()function first drops the app’s tables (using
OC\SchemaWrapper) and resets the
oc_migrationstable to reflect that
OC\SchemaWrapper::performDropTableCalls()is needed to carry out the drops itself.
- Then an appropriate
occ migrations:migratecommand is issued to migrate to the previous version (just before the critical migration)
- The main test just uses
occagain to perform the single migration and check some constraints.
The problem here is that the NC core somehow seems to cache the dropped tables: In the first test case, everything works as expected. The removal of the table is carried out and the test is run.
For any further test case, however, the NC core (aka
OC\SchemaWrapper) has the cached information that the relevant table was dropped and refuses to drop it again. As the recreation was done outside using
SchemaWrapper is not aware of the outdated cache.
The alternative to reloading the cache was to use a completely new instance of
setUp() does something like
$app = new App('cookbook'); $this->container = $app->getContainer();
The container is used to query for the
SchemaWrapper. So, it seems that the created object is saved in the container and will be reused in the next invocations. Therefore I tried to use the process separation of PHPUnit. Unfortunately, I am running into issues related with serializing of Closure objects in the internals of PHPUnit. I just asked on stack overflow but I am not sure about the output given my recent experience there.
So the main questions become:
- Has anyone realized an integration testing approach with setup of the fixtures?
- Can I somehow reset the container of an app in order to start fresh?
- Can I force the schema to be reread from the DB?