{"id":15284058,"url":"https://github.com/creativestyle/app-http-server-mock","last_synced_at":"2026-02-22T04:35:23.469Z","repository":{"id":56958964,"uuid":"158749772","full_name":"creativestyle/app-http-server-mock","owner":"creativestyle","description":"An minimal app http server based on PHP cli-server for use in tests","archived":false,"fork":false,"pushed_at":"2018-11-22T21:25:36.000Z","size":6,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-11-27T17:15:03.884Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creativestyle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-22T21:01:54.000Z","updated_at":"2020-03-13T11:46:49.000Z","dependencies_parsed_at":"2022-08-21T04:30:09.006Z","dependency_job_id":null,"html_url":"https://github.com/creativestyle/app-http-server-mock","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/creativestyle/app-http-server-mock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativestyle%2Fapp-http-server-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativestyle%2Fapp-http-server-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativestyle%2Fapp-http-server-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativestyle%2Fapp-http-server-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creativestyle","download_url":"https://codeload.github.com/creativestyle/app-http-server-mock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativestyle%2Fapp-http-server-mock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29704824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-22T03:17:42.375Z","status":"ssl_error","status_checked_at":"2026-02-22T03:17:31.622Z","response_time":110,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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-09-30T14:48:56.272Z","updated_at":"2026-02-22T04:35:23.439Z","avatar_url":"https://github.com/creativestyle.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Travis Build Status](https://travis-ci.org/creativestyle/app-http-server-mock.svg?branch=master)\n\nPHP HTTP App Server for use in tests\n====================================\n\nThis library allows to query HTTP endpoints in your unit/integration tests without spinning up a whole webserver.\n\nIt uses PHP's built-in web-server underneath, but it's completely opaque and you don't have to worry about anything.\n\nUsage\n=====\n\n_WARNING_ This has to be installed as a composer dependency - it may not work if you just drop it in.\n\n```\ncomposer require --dev creativestyle/app-http-server-mock\n``` \n\nNow you need to subclass `Creativestyle\\AppHttpServerMock\\Server` and implement the only abstract method `registerRequestHandlers`:\n\n```php\n\u003c?php\n\nnamespace YourNamespace;\n\nuse Creativestyle\\AppHttpServerMock\\Server;\nuse Symfony\\Component\\HttpFoundation\\Request;\nuse Symfony\\Component\\HttpFoundation\\Response;\n\nclass YourTestServer extends Server\n{\n    protected function registerRequestHandlers()\n    {\n        $this-\u003eregisterRequestHandler('GET', '/', function(Request $request) {\n            return new Response('Hello');\n        });\n        \n        $this-\u003eregisterRequestHandler(['PUT', 'POST'], '/number/(?\u003cnum\u003e\\d+)/test', function(Request $request, array $args) {\n            return [\n                'arrays' =\u003e [\n                    'are',\n                    'transformed',\n                    'into',\n                    'json' =\u003e ['how' =\u003e 'automatically']\n                ],\n                'your_method' =\u003e $request-\u003egetMethod(),\n                'your_number' =\u003e $args['num']\n            ];\n        });\n    }\n}\n```\n\nAnd now you can just use your server in the tests:\n\n```php\n\u003c?php\n\nnamespace YouNamespace\\Tests;\n\nuse YourNamespace\\YourTestServer;\nuse GuzzleHttp\\Client;\nuse GuzzleHttp\\Exception\\ConnectException;\nuse PHPUnit\\Framework\\TestCase;\n\nclass YourTest extends TestCase\n{\n    /**\n     * @var YourTestServer\n     */\n    private static $testServer;\n\n    public static function setUpBeforeClass()\n    {\n        self::$testServer = new YourTestServer();\n        self::$testServer-\u003estart();\n    }\n\n    public static function tearDownAfterClass()\n    {\n        self::$testServer-\u003estop();\n    }\n\n    private function getClient()\n    {\n        return new Client([\n            'base_uri' =\u003e self::$testServer-\u003egetBaseUrl(),\n            'http_errors' =\u003e false\n        ]);\n    }\n\n    public function testSomething()\n    {\n        $response = $this-\u003egetClient()-\u003eget('/');\n\n        $this-\u003eassertEquals(200, $response-\u003egetStatusCode());\n        $this-\u003eassertEquals('Hello', $response-\u003egetBody()-\u003egetContents());\n    }\n}\n```\n\nOf course you could use the server in the `setUp()` and `tearDown()` methods but it's non-optimal from the perf.\nperspective as the server would be started/stopped before/after each test.\n\nTo get more usage examples and see what's possible see the `/tests` subdirectory of this package - it should be all\nself-explanatory.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreativestyle%2Fapp-http-server-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreativestyle%2Fapp-http-server-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreativestyle%2Fapp-http-server-mock/lists"}