{"id":27899487,"url":"https://github.com/roave/behat-psr11extension","last_synced_at":"2025-05-05T19:35:21.524Z","repository":{"id":23787282,"uuid":"99851336","full_name":"Roave/behat-psr11extension","owner":"Roave","description":"PSR-11 Container extension for Behat","archived":false,"fork":false,"pushed_at":"2025-04-28T20:29:06.000Z","size":320,"stargazers_count":41,"open_issues_count":11,"forks_count":6,"subscribers_count":12,"default_branch":"2.6.x","last_synced_at":"2025-04-28T21:39:40.232Z","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/Roave.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-08-09T20:44:50.000Z","updated_at":"2025-04-26T06:33:40.000Z","dependencies_parsed_at":"2024-02-29T17:52:16.573Z","dependency_job_id":"7aadc08a-b096-4ab2-87db-cc8e657c9956","html_url":"https://github.com/Roave/behat-psr11extension","commit_stats":{"total_commits":91,"total_committers":9,"mean_commits":10.11111111111111,"dds":0.5714285714285714,"last_synced_commit":"95182913a347386d5a11ed3a806724ca34b2e61d"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roave%2Fbehat-psr11extension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roave%2Fbehat-psr11extension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roave%2Fbehat-psr11extension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Roave%2Fbehat-psr11extension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Roave","download_url":"https://codeload.github.com/Roave/behat-psr11extension/tar.gz/refs/heads/2.6.x","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252563166,"owners_count":21768414,"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":"2025-05-05T19:33:56.565Z","updated_at":"2025-05-05T19:35:21.516Z","avatar_url":"https://github.com/Roave.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PSR-11 Container extension for Behat\n\n[![Build Status](https://travis-ci.org/Roave/behat-psr11extension.svg?branch=master)](https://travis-ci.org/Roave/behat-psr11extension) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Roave/behat-psr11extension/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Roave/behat-psr11extension/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/Roave/behat-psr11extension/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Roave/behat-psr11extension/?branch=master) [![Latest Stable Version](https://poser.pugx.org/roave/behat-psr11extension/v/stable)](https://packagist.org/packages/roave/behat-psr11extension) [![License](https://poser.pugx.org/roave/behat-psr11extension/license)](https://packagist.org/packages/roave/behat-psr11extension)\n\nAllows injecting services from a PSR-11-compatibile container in a Behat context.\n\nCreated with lots of help from [@ciaranmcnulty](https://github.com/ciaranmcnulty).\n\n## Usage\n\nFirst require the extension and dependencies with Composer:\n\n```bash\n$ composer require --dev roave/behat-psr11extension\n```\n\nFirst, if you don't already have one, create a file that will be included by the extension that returns a PSR-11\ncompatible container, for example using `Laminas\\ServiceManager`:\n\n```php\n\u003c?php\ndeclare(strict_types=1);\n\nuse Laminas\\ServiceManager\\Config;\nuse Laminas\\ServiceManager\\ServiceManager;\n\n// Load configuration\n$config = require __DIR__ . '/config.php';\n\n// Build container\n$container = new ServiceManager();\n(new Config($config['dependencies']))-\u003econfigureServiceManager($container);\n\n// Inject config\n$container-\u003esetService('config', $config);\n\nreturn $container;\n```\n\nThen enable the extension in `behat.yml`:\n\n```yaml\n  extensions:\n    Roave\\BehatPsrContainer\\PsrContainerExtension:\n      container: 'config/container.php'\n```\n\nThen enable the use of the `psr_container` service container (this is provided by the extension) in your `behat.yml`\nsuite configuration, for example:\n\n```yaml\ndefault:\n  suites:\n    my_suite:\n      services: \"@psr_container\"\n```\n\nAnd finally, add the names of any services required by your contexts in `behat.yml`, for example:\n\n```yaml\ndefault:\n  suites:\n    my_suite:\n      services: \"@psr_container\"\n      contexts:\n        - MyBehatTestSuite\\MyContext:\n          - \"@Whatever\\\\Service\\\\Name\"\n```\n\nYou can also use behat's built-in [autowire feature](https://github.com/Behat/Behat/pull/1071), to automatically inject the dependencies to the context:\n\n```yaml\ndefault:\n  suites:\n    my_suite:\n      autowire: true\n      services: \"@psr_container\"\n      contexts:\n        - MyBehatTestSuite\\MyContext\n```\n\nIf for some reason you want to use a name other than `psr_container` for the container (e.g. collision with another extension) this can\nbe overridden:\n\n```yaml\n  extensions:\n    Roave\\BehatPsrContainer\\PsrContainerExtension:\n      container: 'config/container.php'\n      name: 'my_container'\n```\n\nJust for clarity (and hopefully ease of understanding), this would be the equivalent of doing this in plain PHP:\n\n```php\n\u003c?php\ndeclare(strict_types=1);\n\n$container = require 'config/container.php';\n\n$context = new \\MyBehatTestSuite\\MyContext($container-\u003eget('Whatever\\Service\\Name'));\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froave%2Fbehat-psr11extension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froave%2Fbehat-psr11extension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froave%2Fbehat-psr11extension/lists"}