Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heimrichhannot/contao-test-utilities-bundle
A bundle containing utilities for easier contao bundle testing.
https://github.com/heimrichhannot/contao-test-utilities-bundle
Last synced: about 1 month ago
JSON representation
A bundle containing utilities for easier contao bundle testing.
- Host: GitHub
- URL: https://github.com/heimrichhannot/contao-test-utilities-bundle
- Owner: heimrichhannot
- License: gpl-3.0
- Created: 2019-05-16T12:53:04.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-07T20:28:56.000Z (over 1 year ago)
- Last Synced: 2024-10-01T16:06:59.221Z (3 months ago)
- Language: PHP
- Size: 21.5 KB
- Stars: 0
- Watchers: 7
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Contao Test Utilities Bundle
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```php
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.
```php
\HeimrichHannot\TestUtilitiesBundle\Singleton\ResetFilesSingletonTrait::resetFileSingletonInstance()
```
`\Contao\Files:.getInstance()` will return a fresh instance.