portrino / codeception-helper-module
Codeception 接受测试的通用帮助模块
Requires
- codeception/codeception: ~2.3
- composer/semver: ~1.4.2
- ocramius/package-versions: ~1.1.3
- symfony/process: ~3.3.10 || ~2.7
Requires (Dev)
- phpstan/phpstan: ^0.8
- phpunit/phpunit: ~6.4
- squizlabs/php_codesniffer: ~3.0.2
README
TYPO3 和 Shopware 的 Codeception 接受测试模块集合。您可以使用此模块作为您的 Codeception 接受测试套件的基座。它提供了一套模块、抽象页面对象和接口,使接受测试在 TYPO3 和 Shopware 的环境中更加简洁和易于使用。
安装
您需要将存储库添加到您的 composer.json 文件中
composer require --dev portrino/codeception-helper-module
模块
您可以使用模块(s)作为其他 Codeception 模块,通过将 '\Codeception\Module\Portrino******' 添加到您的 Codeception 套件配置中启用的模块中。
数据库模块
modules: enabled: - \Portrino\Codeception\Module\Database: depends: Db no_reset: true # do not reset database after testsuite
更新 codeception 构建
codecept build
方法
truncateTableInDatabase($table)
截断 $table
。
$I->truncateTableInDatabase($table);
deleteFromDatabase($table, $criteria)
从 $table
中删除符合 $criteria
的行(s)。
$I->deleteFromDatabase($table, $criteria);
TYPO3 模块
modules: enabled: - \Portrino\Codeception\Module\Typo3: depends: Asserts domain: www.example.com
更新 codeception 构建
codecept build
方法
executeCommand
执行指定的 typo3_console $command
。
$I->executeCommand($command, $arguments = [], $environmentVariables = [])
executeSchedulerTask
执行在调度模块中注册的任务。
$I->executeSchedulerTask($taskId, $force = false, $environmentVariables = [])
flushCache
首先清除 TYPO3 核心缓存,然后清除扩展的缓存。
$I->flushCache($force = false, $filesOnly = false)
flushCacheGroups
清除指定组中的所有缓存。默认有效的组名是
- all
- lowlevel
- pages
- system
$I->flushCacheGroups($groups)
importIntoDatabase
将 $file 导入数据库。
$I->importIntoDatabase($file)
Shopware 模块
modules: enabled: - \Portrino\Codeception\Module\Shopware: depends: Asserts bin-dir:
更新 codeception 构建
codecept build
方法
executeCommand
执行指定的 shopware_console $command
。
$I->executeCommand($command, $arguments = [], $environmentVariables = []);
runSqlCommand
在shopware_console中执行SQL查询。
$I->runSqlCommand($sql);
activatePlugin
激活Shopware插件。
$I->activatePlugin($plugin);
installPlugin
安装Shopware插件。如果激活= true,插件将在安装后激活。
$I->installPlugin($plugin, $activate);
refreshPluginList
刷新Shopware插件列表。在安装插件之前有时需要调用此功能。
$I->refreshPluginList();
regenerateThemeCache
重新生成主题缓存。
$I->regenerateThemeCache();
clearCache
清除Shopware缓存。
$I->clearCache();
setPluginConfiguration
通过插件名、配置键和配置值设置Shopware插件的配置。
- 您可以使用$shop参数设置指定商店的配置
$I->setPluginConfiguration($plugin, $key, $value, $shop = 1);
接口
您应该使用在接口中定义的一些常量,以防止拼写错误并使重构更容易。
TYPO3
\Portrino\Codeception\Interfaces\DatabaseTables\Typo3Database
\Portrino\Codeception\Interfaces\Cookies\Typo3Cookie
\Portrino\Codeception\Interfaces\Commands\Typo3Command
示例
$I->seeInDatabase( \Portrino\Codeception\Interfaces\DatabaseTables\Typo3::PAGES, [ 'uid' => 123, ] );
Shopware
\Portrino\Codeception\Interfaces\DatabaseTables\ShopwareDatabase
\Portrino\Codeception\Interfaces\Cookies\ShopwareCookie
\Portrino\Codeception\Interfaces\Commands\ShopwareCommand
$I->seeInDatabase( \Portrino\Codeception\Interfaces\DatabaseTables\Shopware::ARTICLE, [ 'id' => 123, ] );
Fixtures Helper
为了简化,我们添加了一个用于Codeception Fixture功能的辅助工具。
请在您的 _bootstrap.php 文件中添加
'__model' => \Portrino\Codeception\Model\Typo3\Typo3FrontendUser::class,
作为您的Fixture数组中的第一个条目。您的Fixture应该看起来像
\Codeception\Util\Fixtures::add( 'your_fixture_name', [ '__model' => \Portrino\Codeception\Model\Typo3\Typo3FrontendUser::class, 'fixtureValueX' => 'X', 'fixtureValueY' => 'Y' ] );
现在您可以使用我们的适配的Fixtures类使用您的Fixture
\Portrino\Codeception\Util\Fixtures::get('your_fixture_name');
提示
使用codeception与shopware
由于Shopware只支持一些非常旧的包版本,如 guzzlehttp/guzzle
或 symfony/process
,我们建议您将所有测试内容放入一个独立的composer.json文件中,位于单独的位置,如 web/tests/Codeception/
。不要将 codeception\codeception
包添加到Shopware的根composer.json中 - 您会遇到麻烦。
自动加载
要自动加载供应商包,您必须在您的composers _bootstrap.php
文件中 require_once 自定义的autoload.php。
require_once(__DIR__ . '/../../../../web/autoload.php');
作者
- André Wuttig - 初始工作,单元测试 - aWuttig
- Leopold Engst - 单元测试,文档 - leen2104
- Axel Böswetter - 错误修复 - EvilBMP
有关参与此项目的贡献者列表,请参阅。