zfegg/expressive-test
Composer 安装命令:
composer require zfegg/expressive-test
包简介
Zend Expressive abstract test case for PHPUnit
README 文档
README
Using test tools like Laravel in Mezzio (Expressive) unit tests.
使用类似Laravel的测试工具在 Mezzio (Expressive) 的单元测试中.
Installation / 安装使用
Install via composer.
composer require zfegg/expressive-test --dev
Usage / 使用
runApp(...) in test.
use Psr\Http\Message\ResponseInterface; use Zfegg\ExpressiveTest\AbstractActionTestCase; class HomePageTest extends AbstractActionTestCase { public function testHome() { $response = $this->runApp( 'POST', '/?test=1', ['body' => '2'], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"a":"b"}', ['cookie' => '3'] ); $this->assertInstanceOf(ResponseInterface::class, $response); } public function testPassMiddlewareOrMockService() { $this->container->setService('some middleware', new PassMiddleware()); $mock = $this->createMock(SomeService::class); $this->container->setService('mock some service', $mock); $response = $this->runApp( 'POST', '/?test=1', ['body' => '2'], ['HTTP_CONTENT_TYPE' => 'application/json'], '{"a":"b"}', ['cookie' => '3'] ); $this->assertInstanceOf(ResponseInterface::class, $response); } }
Simple test methods like Laravel
use Psr\Http\Message\ResponseInterface; use Zfegg\ExpressiveTest\AbstractActionTestCase; class HomePageTest extends AbstractActionTestCase { public function testHome() { /* $this->get($uri, $headers = []); $this->getJson($uri, $headers = []); $this->post($uri, $data = [], $headers = []); $this->postJson($uri, $data = [], $headers = []); $this->put($uri, $data = [], $headers = []); $this->putJson($uri, $data = [], $headers = []); $this->patch($uri, $data = [], $headers = []); $this->patchJson($uri, $data = [], $headers = []); $this->delete($uri, $data = [], $headers = []); $this->json($method, $uri, $data = [], $headers = []); $this->call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null); */ $response = $this->getJson('/?test=1'); $response->assertOk(); $response->assertSuccessful(); } public function testRedirectLogin() { $response = $this->getJson('/redirect'); $response->assertRedirect('/login'); } }
Test support methods
get($uri, $headers = [])getJson($uri, $headers = [])post($uri, $data = [], $headers = [])postJson($uri, $data = [], $headers = [])put($uri, $data = [], $headers = [])putJson($uri, $data = [], $headers = [])patch($uri, $data = [], $headers = [])patchJson($uri, $data = [], $headers = [])delete($uri, $data = [], $headers = [])json($method, $uri, $data = [], $headers = [])call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null)
Response assert methods
assertCookieassertCookieExpiredassertCookieMissingassertCookieNotExpiredassertCreatedassertDontSeeassertDontSeeTextassertExactJsonassertForbiddenassertHeaderassertHeaderMissingassertJsonassertJsonCountassertJsonMessageassertJsonMissingassertJsonMissingExactassertJsonPathassertJsonStructureassertLocationassertNoContentassertNotFoundassertOkassertRedirectassertSeeassertSeeTextassertStatusassertSuccessfulassertUnauthorized
PassMiddleware
For pass a middleware. As default it will pass ErrorHandler::class.
use Psr\Http\Message\ResponseInterface; use Zfegg\ExpressiveTest\AbstractActionTestCase; use Zfegg\ExpressiveTest\PassMiddleware; class HomePageTest extends AbstractActionTestCase { public function testHome() { // Pass a authentication middleware. $this->container->setService(AuthenticationMiddleware::class, PassMiddleware::class); $response = $this->getJson('/api/users'); $response->assertOk(); } }
统计信息
- 总下载量: 910
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-03-23