heimrichhannot / contao-test-utilities-bundle
A bundle containing utilities for easier contao bundle testing.
Installs: 7 675
Dependents: 4
Suggesters: 0
Security: 0
Stars: 0
Watchers: 7
Forks: 0
Open Issues: 0
Type:contao-bundle
Requires
- php: ^7.1 || ^8.0
- contao/core-bundle: ^4.4 || ^5.0
- phpunit/phpunit: ^6.5 || ^7.0 || ^8.0 || ^9.0
- symfony/dependency-injection: ^3.4 || ^4.0 || ^5.0 || ^6.0
- symfony/http-kernel: ^3.4 || ^4.0 || ^5.0 || ^6.0
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.