heimrichhannot/contao-test-utilities-bundle
A bundle containing utilities for easier contao bundle testing.
Maintainers
Package info
github.com/heimrichhannot/contao-test-utilities-bundle
Type:contao-bundle
pkg:composer/heimrichhannot/contao-test-utilities-bundle
0.1.8
2025-12-11 09:23 UTC
Requires
- php: ^8.1
- contao/core-bundle: ^4.13 || ^5.0
- phpunit/phpunit: ^8.0 || ^9.0 || ^10.0 || ^11.0
- symfony/dependency-injection: ^5.4 || ^6.0 || ^7.0
- symfony/http-kernel: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- contao/contao-rector: dev-main
- contao/manager-plugin: ^2.13
- phpstan/phpstan: ^2.1
- phpstan/phpstan-symfony: ^2.0
- rector/rector: ^2.2
- symplify/easy-coding-standard: ^13.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
LGPL-3.0-or-later cfbe7f3e6ba930444075da9a26c96bf2399cb169
README
This bundle helps with recurring tasks when testing bundles for contao cms.
Install
composer require --dev heimrichhannot/contao-test-utilities-bundle
Content
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->setName('ce_skip'); $templateMock->getName(); $templateMock->setData(['foo' => 'bar']); $templateMock->getData(); // and __get, __set, __isset } public function testModelMock() { $model = $this->mockModelObject(\Contao\PageModel::class, []); $model->row(); // and __get, __set, __isset } }
Singletons
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.
\HeimrichHannot\TestUtilitiesBundle\Singleton\ResetFilesSingletonTrait::resetFileSingletonInstance()
\Contao\Files:.getInstance() will return a fresh instance.
