{"id":14984003,"url":"https://github.com/persata/symfonyapiextension","last_synced_at":"2025-07-13T20:31:54.793Z","repository":{"id":57037926,"uuid":"105094274","full_name":"Persata/SymfonyApiExtension","owner":"Persata","description":"Provides functionality for testing Symfony APIs with Behat.","archived":false,"fork":false,"pushed_at":"2019-10-16T09:30:29.000Z","size":38,"stargazers_count":1,"open_issues_count":1,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-18T09:54:02.927Z","etag":null,"topics":["api","behat","behat-extension","symfony"],"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/Persata.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2017-09-28T02:45:19.000Z","updated_at":"2018-08-07T09:45:48.000Z","dependencies_parsed_at":"2022-08-23T21:00:26.291Z","dependency_job_id":null,"html_url":"https://github.com/Persata/SymfonyApiExtension","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Persata%2FSymfonyApiExtension","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Persata%2FSymfonyApiExtension/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Persata%2FSymfonyApiExtension/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Persata%2FSymfonyApiExtension/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Persata","download_url":"https://codeload.github.com/Persata/SymfonyApiExtension/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225914421,"owners_count":17544535,"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":["api","behat","behat-extension","symfony"],"created_at":"2024-09-24T14:08:18.260Z","updated_at":"2024-11-22T14:36:34.986Z","avatar_url":"https://github.com/Persata.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Symfony API Extension [![License](https://img.shields.io/packagist/l/persata/symfony-api-extension.svg)](https://packagist.org/packages/persata/symfony-api-extension) [![Version](https://img.shields.io/packagist/v/persata/symfony-api-extension.svg)](https://packagist.org/packages/persata/symfony-api-extension) [![Build Status](https://travis-ci.org/Persata/SymfonyApiExtension.svg?branch=master)](https://travis-ci.org/Persata/SymfonyApiExtension)\n\nProvides functionality for testing Symfony APIs with Behat.\n\nThis package offers an `ApiClient` class that can be shared between all relevant contexts that require being able to modify the request or inspect the response. \n\nRequires the FriendsOfBehat [SymfonyExtension](https://github.com/FriendsOfBehat/SymfonyExtension).\n\n## Usage\n\n1. Install via Composer:\n\n    ```bash\n    $ composer require persata/symfony-api-extension --dev\n    ```\n\n2. Enable and configure in your Behat configuration:\n\n    ```yaml\n    # behat.yml\n    default:\n        suites:\n            default:\n                contexts:\n                    - Persata\\SymfonyApiExtension\\Context\\ApiContext: ~\n\n        extensions:\n            Persata\\SymfonyApiExtension: ~\n            FriendsOfBehat\\SymfonyExtension:\n                kernel:\n                    bootstrap: vendor/autoload.php\n    ```\n\n## Additional Custom Contexts\n\nThis package provides a `ContextInitializer` that will set the shared `ApiClient` on any Behat Contexts that implement the `ApiClientAwareContext`. It is best to extend the `RawApiContext` as this already includes the getter \u0026 setter for the `ApiClient` instance.\n\n## ContextServiceExtension Integration\n\nIf using the FriendsOfBehat [ContextServiceExtension](https://github.com/FriendsOfBehat/ContextServiceExtension), declare the `ApiContext` service like so:\n\n```yaml\nservices:\n    # ...\n    Persata\\SymfonyApiExtension\\Context\\ApiContext:\n        tags:\n            - { name: fob.context_service }\n```\n\nIf you need additional context services with access to the same shared ApiClient instance, have them extend `RawApiContext` and then declare the service like so:\n\n```yaml\nservices:\n    # ...\n    TheClass\\Of\\Your\\CustomContext:\n        tags:\n            - { name: fob.context_service }\n```\n\n## FOSRest Form Validation\n\nIf you are using the FOSRestBundle within your Symfony application and are making use of the [form response features](https://symfony.com/doc/master/bundles/FOSRestBundle/2-the-view-layer.html#forms-and-views), there is an additional `FOSRestFormValidationContext` class provided for testing for the presence or omission of errors:\n\n```gherkin\nThen the JSON response should have the error \"This value should not be null.\" at \"user.firstName\"\nAnd the JSON response should not have any errors on \"user.lastName\"\n```\n\n## Example Scenario\n```gherkin\nScenario: Testing Basic JSON Endpoint\n    Given the \"Authorization\" request header is \"Bearer MyToken\"\n    When the request is sent using GET to \"/example-endpoint\"\n    Then the response status code should be 200\n    And the response content type should be JSON\n    And the response content should be valid JSON\n    And the JSON response should be\n    \"\"\"\n    {\n        \"hello\": \"world\"\n    }\n    \"\"\"\n    And the JSON response should have the structure\n    \"\"\"\n    [\n        \"hello\"\n    ]\n    \"\"\"\n```\n\n## Extension Configuration\n```yaml\n# behat.yml\ndefault:\n    extensions:\n        Persata\\SymfonyApiExtension:\n            base_url: 'http://my-api.local' # Base URL used for requests sent to the Symfony kernel. Defaults to null.\n            files_path: \"%paths.base%/src/Behat/Resources/fixtures/\" # Base directory of files to be used for upload tests. Defaults to null.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersata%2Fsymfonyapiextension","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpersata%2Fsymfonyapiextension","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpersata%2Fsymfonyapiextension/lists"}