mileschou/slim-test
Composer 安装命令:
composer require --dev mileschou/slim-test
包简介
A simple test helper for Slim Framework 3
README 文档
README
A simple test helper for Slim Framework 3
The repository has some example in tests folder. app.php is a definition use simple Slim router, SlimCaseTest.php is testing for SlimCase class, and ClientTest.php is testing for Client class. You can use Client If you want to use PHPUnit style to write test, or use SlimCase in Codeception style.
Installation with Composer
$ composer require --dev mileschou/slim-test
Using object in PHPUnit
First, prepare your Slim App in test code and pass to SlimCase constructor.
use MilesChou\Slim\Test\SlimCase; class SlimAppTest extends PHPUnit_Framework_TestCase { public function setUp() { $app = require 'path/to/app.php'; $this->slimCase = new SlimCase($app); } }
Now, you can use Codeception Style to make assertion.
public function testSeeResponseOk() { // Arrange $url = '/will/return/ok'; // Act $this->slimCase->sendGET($url); // Assert $this->slimCase->seeResponseOk(); }
The visibility of Client object in SlimCase is public. That means you can use Client like
$this->slimCase->client->get($url);
It's unsafe to access client object directly. The visibility will modify to
privatein the future.
Using trait in PHPUnit
You can use ClientTrait or SlimCaseTrait in PHPUnit, too. Here is an example:
use MilesChou\Slim\Test\SlimCaseTrait; class SlimAppTest extends PHPUnit_Framework_TestCase { use SlimCaseTrait; public function setUp() { $app = require 'path/to/app.php'; $this->setSlimApp($app); } public function tearDown() { $this->setSlimApp(null); } public function testSeeResponseOk() { // Arrange $url = '/will/return/ok'; // Act $this->sendGET($url); // Assert $this->seeResponseOk(); } }
Using in Behat
It's easy to using Slim Test in Behat. For example, I have a feature file
# features/app.feature Feature: an example testing use behat Scenario: Test assert response is okay Given a route named "/will/return/ok" When visit "/will/return/ok" Then I should see response okay
And implement context file easily
// features/bootstrap/FeatureContext.php use Behat\Behat\Context\Context; use Behat\Behat\Context\SnippetAcceptingContext; use MilesChou\Slim\Test\SlimCaseTrait; class FeatureContext implements Context, SnippetAcceptingContext { use SlimCaseTrait; public function __construct() { // bootstrap your slim app $app = require __DIR__ . '/../../app.php'; $this->setSlimApp($app); } /** @Given a route named :url */ public function aRouteNamed($url) { /** Do nothing */ } /** @When visit :url */ public function visit($url) { $this->sendGET($url); } /** @Then I should see response okay */ public function iShouldSeeResponseOkay() { $this->seeResponseOk(); } }
Tests
Execute all test suite use PHPUnit and Behat
$ php vendor/bin/phpunit
$ php vendor/bin/behat
You can use composer scripts, too
$ composer test
Run PHP built-in server if you want to check HTTP response via browser
$ php -S 0.0.0.0:8080 -t public
License
The Slim Test is licensed under the MIT license. See License File for more information.
mileschou/slim-test 适用场景与选型建议
mileschou/slim-test 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 9.49k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「testing」 「slim」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mileschou/slim-test 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mileschou/slim-test 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mileschou/slim-test 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Testing Suite For Lumen like Laravel does.
Secure session middleware for Slim 3 framework
The PHP SDK for Checkmango
Adds request-parameter validation to the SLIM 3.x PHP framework
Slim Framework 3 CSRF protection middleware utilities
Slim starter / Slim skeleton package to boost your development with Slim framework
统计信息
- 总下载量: 9.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-21