there4/slim-test-helpers
最新稳定版本:v2.1.3
Composer 安装命令:
composer require there4/slim-test-helpers
包简介
Integration testing helpers for the Slim Framework
关键字:
README 文档
README
Integration testing helpers for the Slim Framework 3
For a full example, please see the companion repo at there4/slim-unit-testing-example.
Example
Here's a test for a very simple endpoint that returns the version from the
application config. We're asserting that Slim responded with a 200 and that
the version matches what we expect.
class VersionTest extends LocalWebTestCase { public function testVersion() { $this->client->get('/version'); $this->assertEquals(200, $this->client->response->getStatusCode()); $this->assertEquals($this->app->config('version'), $this->client->response->getBody()); } }
Here is an example on how to pass data to a POST endpoint in a test case and
retrieve it later in the endpoint. We are passing encoded JSON data in the body
of the request. The data is retrieved in the endpoint using
$app->request->getBody().
// test file class UserTest extends LocalWebTestCase { public function testVersion() { ...... $data = array("user" => 1); $data = json_encode($data); $this->client->post('/user', $data); ...... } } // endpoint file ..... $app->post('/user', function() use ($app) { ..... $data = $app->request->getBody(); $data = json_decode($data, true); ...... });
Example with DbUnit
If you wish to use Database fixture, use class WebDbTestCase. Caution: Make
sure the names you use for you fixture models won't conflict with your actual
DB tables.
class LocalDbWebTestCase extends \There4\Slim\Test\WebDbTestCase { /** * You must implement this method * @return PHPUnit_Extensions_Database_DataSet_IDataSet */ public function getDataSet() { return $this->createFlatXMLDataSet( dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fixture.xml' ); } }
Setup
You'll need a bootstrap file for phpunit that can instantiate your Slim application. You can see [an example boostrap] in the sample app.
You'll implement your own getSlimInstance() method that returns an instance of your app by extending the WebTestCase helper.
统计信息
- 总下载量: 255.53k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 61
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-03-14