luyadev/luya-testsuite
Composer 安装命令:
composer require luyadev/luya-testsuite
包简介
TestCases and Data for LUYA Modules and Components. Makes testing less pain.
README 文档
README
Providing PHPUnit Testcases and a built in Webserver to test your Application, Modules, Components, APIs or Classes.
Whats included?
Test Cases
- Web application test case
- Console application test case
- Server (for APIs) test case
- CMS Block test case
- NgRest test case (for model, controller and API)
Traits
- Message file compare trait
- Migration file check trait
Fixtures
- ActiveRecord fixture creates the table on loading based from array or rule definition.
See the full Documentation
Install
Add the luyadev/luya-testsuite package to the require-dev section of your composer.json file:
composer require luyadev/luya-testsuite --dev
Create a new folder tests inside your appliation folder and create a test classes:
namespace app\tests; use Yii; class MyTest extends \luya\testsuite\cases\WebApplicationTestCase { public function getConfigArray() { return [ 'id' => 'mytestapp', 'basePath' => dirname(__DIR__), ]; } public function testInstance() { // add your phpunit tests here, like: $this->assertInstanceOf('luya\web\Application', Yii::$app); $this->assertInstanceOf('luya\base\Boot', $this->boot); $this->assertInstanceOf('luya\web\Application', $this->app); } }
To run the unit tests while (assuming your tests are in directory tests/) run in your terminal:
./vendor/bin/phpunit tests/
In order to support sqlite fixtures install:
sudo apt-get install php-sqlite3
Example Test Cases
Some example in how to use the LUYA Testsuite for different scenarios.
Testing API and Application
When working with APIs or Customer Websites somtimes you just want to test the Website itself, what is the response, does all the pages still work after my update? Therefore we have luya\testsuite\cases\ServerTestCase.
This example will run your LUYA application within a PHP Webserver and test the response status codes or contents for a set of given pages. In order to run this example create a MyWebsiteTest.php file inside the tests folder.
namespace app\tests; class MyWebsiteTest extends ServerTestCase { public function getConfigArray() { return [ 'id' => 'mytestapp', 'basePath' => dirname(__DIR__), ]; } public function testSites() { $this->assertUrlHomepageIsOk(); // checks the root url like: http://localhost/mywebsite.com $this->assertUrlIsOk('about'); // checks: http://localhost/mywebsite.com/about $this->assertUrlGetResponseContains('about/me', 'Hello World'); // checks: http://localhost/mywebsite.com/about/me $this->assertUrlIsError('errorpage'); // checks: http://localhost/mywebsite.com/errorpage } }
As the Webserver process may run from a different permission level you have to ensure the assets/runtime folder has the required permissions.
Controller Function Test
We're using getMockBuilder() as shown in the multiple examples in the PHPUnit to setup the DefaultController and assert the registered module addressbook. To test the the runtime exception (caused by a database error), we use the mock method function:
public function testActionIndex() { $module = Yii::$app->getModule('addressbook'); $this->assertInstanceOf('luya\addressbook\frontend\Module', $module); $mock = $this->getMockBuilder(DefaultController::class) ->setConstructorArgs(["id" => "default", "module" => $module]) ->getMock(); $mock->method("actionIndex"); }
luyadev/luya-testsuite 适用场景与选型建议
luyadev/luya-testsuite 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 105.63k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2017 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「module」 「luya」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 luyadev/luya-testsuite 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 luyadev/luya-testsuite 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 luyadev/luya-testsuite 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The LUYA CMS module provides a full functional Content Management System for adding contents based on blocks.
LUYA Generic content
LUYA Bootstrap 3 content
Bootstrap4 Assets and Helper classes like ActiveForm for LUYA and Yii2.
The LUYA Privacy extension provides helpers for privacy.
Matomo (former piwik) analytics
统计信息
- 总下载量: 105.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 26
- 依赖项目数: 75
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-04