{"id":17236317,"url":"https://github.com/there4/slim-test-helpers","last_synced_at":"2025-04-06T07:12:22.458Z","repository":{"id":14989192,"uuid":"17714446","full_name":"there4/slim-test-helpers","owner":"there4","description":"Integration testing helpers for the Slim Framework","archived":false,"fork":false,"pushed_at":"2024-03-26T08:25:25.000Z","size":80,"stargazers_count":60,"open_issues_count":6,"forks_count":28,"subscribers_count":12,"default_branch":"master","last_synced_at":"2025-03-30T05:08:47.734Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/there4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-13T15:13:48.000Z","updated_at":"2022-10-26T18:07:30.000Z","dependencies_parsed_at":"2024-06-18T14:01:52.773Z","dependency_job_id":"d773cdb8-2b2b-4389-80aa-931676ad0ec9","html_url":"https://github.com/there4/slim-test-helpers","commit_stats":{"total_commits":69,"total_committers":19,"mean_commits":"3.6315789473684212","dds":0.7391304347826086,"last_synced_commit":"a9f5885d0587f6aa4f582846c3cf6722ef3bdf47"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-test-helpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-test-helpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-test-helpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/there4%2Fslim-test-helpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/there4","download_url":"https://codeload.github.com/there4/slim-test-helpers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247445671,"owners_count":20939958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T05:35:53.824Z","updated_at":"2025-04-06T07:12:22.426Z","avatar_url":"https://github.com/there4.png","language":"PHP","funding_links":[],"categories":["Packages and Middleware"],"sub_categories":["Videos"],"readme":"# Slim Test Helpers [![Build Status](https://travis-ci.org/there4/slim-test-helpers.svg?branch=master)](https://travis-ci.org/there4/slim-test-helpers) [![Code Climate](https://codeclimate.com/github/there4/slim-test-helpers/badges/gpa.svg)](https://codeclimate.com/github/there4/slim-test-helpers) [![Test Coverage](https://codeclimate.com/github/there4/slim-test-helpers/badges/coverage.svg)](https://codeclimate.com/github/there4/slim-test-helpers/coverage)\n\u003e Integration testing helpers for the Slim Framework 3\n\nFor a full example, please see the companion repo at [there4/slim-unit-testing-example][example].\n\n## Example\n\nHere's a test for a very simple endpoint that returns the version from the\napplication config. We're asserting that Slim responded with a `200` and that\nthe version matches what we expect.\n\n```php\nclass VersionTest extends LocalWebTestCase\n{\n    public function testVersion()\n    {\n        $this-\u003eclient-\u003eget('/version');\n        $this-\u003eassertEquals(200, $this-\u003eclient-\u003eresponse-\u003egetStatusCode());\n        $this-\u003eassertEquals($this-\u003eapp-\u003econfig('version'), $this-\u003eclient-\u003eresponse-\u003egetBody());\n    }\n}\n```\n\nHere is an example on how to pass data to a POST endpoint in a test case and \nretrieve it later in the endpoint. We are passing encoded JSON data in the body\nof the request. The data is retrieved in the endpoint using \n`$app-\u003erequest-\u003egetBody()`.\n\n```php\n// test file\nclass UserTest extends LocalWebTestCase\n{\n    public function testVersion()\n    {\n        ......\n        $data = array(\"user\" =\u003e 1);\n        $data = json_encode($data);\n        $this-\u003eclient-\u003epost('/user', $data);\n        ......\n    }\n}\n\n// endpoint file\n.....\n$app-\u003epost('/user', function() use ($app) {\n    .....\n    $data = $app-\u003erequest-\u003egetBody();\n    $data = json_decode($data, true);\n    ......\n});\n```\n\n### Example with DbUnit\n\nIf you wish to use Database fixture, use class `WebDbTestCase`. *Caution*: Make \nsure the names you use for you fixture models won't conflict with your actual\nDB tables.\n\n```php\nclass LocalDbWebTestCase extends \\There4\\Slim\\Test\\WebDbTestCase\n{\n    /**\n     * You must implement this method\n     * @return PHPUnit_Extensions_Database_DataSet_IDataSet\n     */\n    public function getDataSet()\n    {\n        return $this-\u003ecreateFlatXMLDataSet(\n            dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fixture.xml'\n        );\n    }\n}\n```\n\n## Setup\n\nYou'll need a bootstrap file for phpunit that can instantiate your Slim application. You can see [an example boostrap] in [the sample app][example].\n\nYou'll implement your own `getSlimInstance()` method that returns an instance of your app [by extending][webtestcase] the `WebTestCase` helper.\n\n[example]: https://github.com/there4/slim-unit-testing-example\n[bootstrap]: https://github.com/there4/slim-unit-testing-example/blob/master/tests/bootstrap.php\n[webtestcase]: https://github.com/there4/slim-test-helpers/blob/master/src/There4/Slim/Test/WebTestCase.php\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthere4%2Fslim-test-helpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthere4%2Fslim-test-helpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthere4%2Fslim-test-helpers/lists"}