heimrichhannot / contao-test-utilities-bundle
包含简化 contao 扩展测试的实用工具包。
0.1.7
2023-08-07 20:28 UTC
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
此工具包有助于在测试 contao cms 扩展时的常规任务。
安装
composer require --dev heimrichhannot/contao-test-utilities-bundle
内容
模拟对象
此工具包提供了一些特质来模拟以下 contao 类型
- 模型
- 模板
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 } }
单例
重置文件单例
建议在测试与它交互的代码时始终重置 Files(单例)类,因为它可以存储来自先前测试的数据(例如容器)。因此,您无需在另一个进程中运行测试方法。
\HeimrichHannot\TestUtilitiesBundle\Singleton\ResetFilesSingletonTrait::resetFileSingletonInstance()
\Contao\Files:.getInstance()
将返回一个新的实例。