A bundle containing utilities for easier contao bundle testing.

0.1.7 2023-08-07 20:28 UTC

This package is auto-updated.

Last update: 2024-05-07 22:01:22 UTC


This bundle helps with recurring tasks when testing bundles for contao cms.


composer require --dev heimrichhannot/contao-test-utilities-bundle


Mocking objects

This bundle provide some traits to mock following contao types:

  • models
  • templates
class Test {
    use \HeimrichHannot\TestUtilitiesBundle\Mock\ModelMockTrait;
    use \HeimrichHannot\TestUtilitiesBundle\Mock\TemplateMockTrait;
    public function testMockTemplate() {
        $templateMock = $this->mockTemplateObject(\Contao\FrontendTemplate::class, 'ce_test');
        $templateMock->setData(['foo' => 'bar']);
        // and __get, __set, __isset
    public function testModelMock() {
        $model = $this->mockModelObject(\Contao\PageModel::class, []);
        // and __get, __set, __isset


Reset Files singleton

It is recommend to always reset the Files (singleton) class when testing code interacting with it, as it can store data from past tests (for example the container). So you don't need to run a test method in another process.


\Contao\Files:.getInstance() will return a fresh instance.