Testing and Classes


I have started writing unit tests for my pimcore bundles with the codeception Tutorial.

However I don’t understand one thing: Why can I not use the already defined classes in var/classes when testing? I use the TestHelper to create and bootstrap a new database for testing, because that makes sense. But why doesn’t the created database include the classes in my project already?

I know I can create the classes by providing a JSON file to their exports, but… Wouldn’t it make much more sense that the tests use the same data classes as the final code? When I change something in a class, I now need to export that classes json, so the tests can use the updated version as well.

I assume I am missing something obivous, because that system doesn’t make a whole lot of sense to me. It produced redundant information about the class definitions: One for production code, one for testing…?


Just in case anybody runs into the same question. I ended up adding the following to the _bootstrap.php file of the test suite:

codecept_debug("Rebuilding classes in test database");
$cmd = new ClassesRebuildCommand();
$input = new ArrayInput(["-c" => true]);
$output = new ConsoleOutput();
$cmd->run($input, $output);

After that, all tests can use Pimcore DataObject classes as they would in production as well.

Make sure thought, that purge_class_directory: false is set in the xxx.suite.yml file.