krajcik/nette-tester-extension
Composer 安装命令:
composer require krajcik/nette-tester-extension
包简介
Extension library for nette tester.
README 文档
README
Easy testing of presenters
Library contains class BasePresenterTester which provide following methods:
- checkRequestNoError - expect that some action of presenter is without error
- checkRequestError - expect that some action of presenter throw error
- checkRedirectTo - expect that some action of presenter return redirect
Authenticator
In default ever request are sent as from unlogged user. If we want test behavior of action when is some user logged in, we can use parameters "$userId" etc. which provide all check* methods. We do not need to know password of user. Simply say that we want be logged in as user with id "$userId".
Default role of logged user is 'admin'. For change role use parameter "$userRole"
Example in practice
!!! Important recomended: Before start tests clear cache !!!
For each presenter to test must be created separated class
<?php require __DIR__ . '/../../../../vendor/autoload.php'; require __DIR__ . '/../../../../vendor/helbrary/nette-tester-extension/src/BasePresenterTester.php'; final class TestAccountPresenter extends \Helbrary\NetteTesterExtension\BasePresenterTester { /** * @var \Model\UserModel */ private $userModel; /** * @var bool|\Model\User */ private $testingUser; /** * TestGoodsPresenter constructor. */ public function __construct() { parent::__construct('Front:Account'); // Here is defined presenter which we want test $this->userModel = $this->container->getByType('\Model\UserModel'); $this->testingUser = $this->userModel->find()->fetch(); // get some user from db } /** * Test detail action of account presenter */ public function testDetail() { // if no user is logged in, expected redirect to Sign in $this->checkRedirectTo(array( 'action' => 'detail', 'id' => 8, // parameter id for action detail ), 'Front:Sign:in'); // if some user is logged in, expected that action detail will be render without error // after send this request is logged in user with id $this->testingUser->id $this->checkRequestNoError(array( 'action' => 'detail', ), 'GET', $this->testingUser->id); } } $testCase = new TestAccountPresenter(); $testCase->run();
Multiple presenter tester in one test
<?php require __DIR__ . '/../../vendor/autoload.php'; require __DIR__ . '/../../vendor/helbrary/nette-tester-extension/src/BasePresenterTester.php'; final class TestPresenterActions extends \Helbrary\NetteTesterExtension\BaseMultiPresenterTester { /** * TestGoodsPresenter constructor. */ public function __construct() { parent::__construct(); } public function testActions() { $actions = [ 'Core:Customers' => [ 'actions' => [ [ 'parameters' => ['action' => 'default'], // optional - default is empty array 'method' => 'GET', // optional - default is GET 'userId' => NULL, // optional - default is NULL 'userRole' => NULL, // optional - default is NULL 'identityData' => NULL, // optional - default is NULL ], [ 'parameters' => ['id' => 1, 'action' => 'default'], ], ] ] ]; $this->checkWithoutErrors($actions); } } $testCase = new TestPresenterActions(); $testCase->run();
krajcik/nette-tester-extension 适用场景与选型建议
krajcik/nette-tester-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.71k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2019 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 krajcik/nette-tester-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 krajcik/nette-tester-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 10.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-02-04