{"id":20827694,"url":"https://github.com/peridot-php/peridot-httpkernel-plugin","last_synced_at":"2025-05-07T21:04:54.920Z","repository":{"id":22310310,"uuid":"25645402","full_name":"peridot-php/peridot-httpkernel-plugin","owner":"peridot-php","description":"A Peridot plugin to simplify testing HttpKernel applications","archived":false,"fork":false,"pushed_at":"2020-01-03T07:35:10.000Z","size":15,"stargazers_count":4,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-07T21:04:48.727Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://peridot-php.github.io/","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/peridot-php.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}},"created_at":"2014-10-23T15:59:52.000Z","updated_at":"2020-01-03T07:35:12.000Z","dependencies_parsed_at":"2022-08-21T02:31:03.091Z","dependency_job_id":null,"html_url":"https://github.com/peridot-php/peridot-httpkernel-plugin","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-httpkernel-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-httpkernel-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-httpkernel-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peridot-php%2Fperidot-httpkernel-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peridot-php","download_url":"https://codeload.github.com/peridot-php/peridot-httpkernel-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252954432,"owners_count":21830903,"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-11-17T23:12:45.965Z","updated_at":"2025-05-07T21:04:54.901Z","avatar_url":"https://github.com/peridot-php.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Peridot HttpKernel Plugin\n=========================\n\n[![Build Status](https://travis-ci.org/peridot-php/peridot-httpkernel-plugin.png)](https://travis-ci.org/peridot-php/peridot-httpkernel-plugin) [![HHVM Status](http://hhvm.h4cc.de/badge/peridot-php/peridot-httpkernel-plugin.svg)](http://hhvm.h4cc.de/package/peridot-php/peridot-httpkernel-plugin)\n\nEasily test [HttpKernel](http://symfony.com/doc/current/components/http_kernel/introduction.html) applications with [Peridot](http://peridot-php.github.io/).\n\nSome HttpKernel based frameworks:\n\n* [Silex](http://silex.sensiolabs.org/)\n* [Laravel] (http://laravel.com/)\n* [Symfony2] (http://symfony.com/what-is-symfony)\n\n##Usage\n\nWe recommend installing this plugin to your project via composer:\n\n```\n$ composer require --dev peridot-php/peridot-httpkernel-plugin:~1.0\n```\n\nYou can register the plugin via your [peridot.php](http://peridot-php.github.io/#plugins) file.\n\n```php\n\u003c?php\nuse Evenement\\EventEmitterInterface;\nuse Peridot\\Plugin\\HttpKernel\\HttpKernelPlugin;\n\nreturn function(EventEmitterInterface $emitter) {\n    //the second argument expects an HttpKernelInterface or a function that returns one\n    HttpKernelPlugin::register($emitter, include __DIR__ . '/app.php');\n};\n```\n\nBy registering the plugin, your Peridot tests will now have a `$client` property available:\n\n```php\n\u003c?php\ndescribe('Api', function() {\n    describe('/info', function() {\n        it('should return info about Peridot', function() {\n            $this-\u003eclient-\u003erequest('GET', '/info');\n            $response = $this-\u003eclient-\u003egetResponse();\n            $info = json_decode($response-\u003egetContent());\n            assert($info-\u003eproject == \"Peridot\", \"project should be Peridot\");\n            assert($info-\u003edescription == \"Event driven testing framework\", \"description should describe Peridot\");\n            assert($info-\u003estyles == \"BDD, TDD\", \"styles should be BDD, TDD\");\n        });\n    });\n\n    describe('/author', function() {\n        it('should return info about the author', function() {\n            $this-\u003eclient-\u003erequest('GET', '/author');\n            $author = json_decode($this-\u003eclient-\u003egetResponse()-\u003egetContent());\n            assert($author-\u003ename == \"Brian Scaturro\", \"author name should be on response\");\n            assert($author-\u003elikes == \"pizza\", \"author should like pizza\");\n        });\n    });\n});\n```\n\nVoilà!\n\nDon't want a client in all of your tests? No problem.\n\n###Using on a test by test basis\n\nLike any other peridot [scope](http://peridot-php.github.io/#scopes), you can mix the `HttpKernelScope` provided by this plugin\non a test by test, or suite by suite basis.\n\n```php\n\u003c?php\nuse Peridot\\Plugin\\HttpKernel\\HttpKernelScope;\n\ndescribe('Api', function() {\n\n    //here we manually mixin the http kernel scope\n    $scope = new HttpKernelScope(include __DIR__ . '/../app.php');\n    $this-\u003eperidotAddChildScope($scope);\n\n    describe('/author', function() {\n        it('should return info about the author', function() {\n            $this-\u003eclient-\u003erequest('GET', '/author');\n            $author = json_decode($this-\u003eclient-\u003egetResponse()-\u003egetContent());\n            assert($author-\u003ename == \"Brian Scaturro\", \"author name should be on response\");\n            assert($author-\u003elikes == \"pizza\", \"author should like pizza\");\n        });\n    });\n});\n```\n\n###Configuring the client property name\n\nIf `$this-\u003eclient` is a little too generic for your tastes, both the scope and plugin take an optional last argument that allows you to\nyou set this.\n\n```php\nHttpKernelPlugin::register($emitter, include __DIR__ . '/app.php', \"browser\");\n$scope = new HttpKernelScope($application, \"browser\");\n```\n\nYour tests now become:\n\n```php\n\u003c?php\nuse Peridot\\Plugin\\HttpKernel\\HttpKernelScope;\n\ndescribe('Api', function() {\n\n    describe('/author', function() {\n        it('should return info about the author', function() {\n            $this-\u003ebrowser-\u003erequest('GET', '/author');\n            $author = json_decode($this-\u003ebrowser-\u003egetResponse()-\u003egetContent());\n            assert($author-\u003ename == \"Brian Scaturro\", \"author name should be on response\");\n            assert($author-\u003elikes == \"pizza\", \"author should like pizza\");\n        });\n    });\n});\n```\n\n##Example specs\n\nThis repo comes with a sample [Silex](http://silex.sensiolabs.org/) application that is tested with this plugin.\n\nTo test examples that are using the plugin, run the following:\n\n```\n$ vendor/bin/peridot -c app/peridot.php app/specs/api.spec.php\n```\n\nTo test examples that are manually adding the scope in, run this:\n\n```\n$ vendor/bin/peridot app/specs/no-plugin.spec.php\n```\n\n##Running plugin tests\n\n```\n$ vendor/bin/peridot specs/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-httpkernel-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperidot-php%2Fperidot-httpkernel-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperidot-php%2Fperidot-httpkernel-plugin/lists"}