PHPackages                             persata/symfony-api-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. persata/symfony-api-extension

ActiveLibrary[API Development](/categories/api)

persata/symfony-api-extension
=============================

Provides functionality for testing Symfony APIs with Behat.

0.2.9(7y ago)15373[1 PRs](https://github.com/Persata/SymfonyApiExtension/pulls)MITPHPPHP ^7.0

Since Oct 2Pushed 6y ago3 watchersCompare

[ Source](https://github.com/Persata/SymfonyApiExtension)[ Packagist](https://packagist.org/packages/persata/symfony-api-extension)[ RSS](/packages/persata-symfony-api-extension/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (6)Versions (18)Used By (0)

Symfony API Extension [![License](https://camo.githubusercontent.com/db6f393351922ba8dc898fd820ad475e1705c0b8629ce5dc620cc2b25ddb5356/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706572736174612f73796d666f6e792d6170692d657874656e73696f6e2e737667)](https://packagist.org/packages/persata/symfony-api-extension) [![Version](https://camo.githubusercontent.com/a43c136a41acb2eb10a1f9e3855a427dc0e48cacb362b3ed5e88788710203a26/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706572736174612f73796d666f6e792d6170692d657874656e73696f6e2e737667)](https://packagist.org/packages/persata/symfony-api-extension) [![Build Status](https://camo.githubusercontent.com/6ac964dfd6089adc0492445873629fd533d01362349ebd7f2edc651eedbdb578/68747470733a2f2f7472617669732d63692e6f72672f506572736174612f53796d666f6e79417069457874656e73696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Persata/SymfonyApiExtension)
========================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#symfony-api-extension---)

Provides functionality for testing Symfony APIs with Behat.

This 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.

Requires the FriendsOfBehat [SymfonyExtension](https://github.com/FriendsOfBehat/SymfonyExtension).

Usage
-----

[](#usage)

1. Install via Composer:

    ```
    $ composer require persata/symfony-api-extension --dev
    ```
2. Enable and configure in your Behat configuration:

    ```
    # behat.yml
    default:
        suites:
            default:
                contexts:
                    - Persata\SymfonyApiExtension\Context\ApiContext: ~

        extensions:
            Persata\SymfonyApiExtension: ~
            FriendsOfBehat\SymfonyExtension:
                kernel:
                    bootstrap: vendor/autoload.php
    ```

Additional Custom Contexts
--------------------------

[](#additional-custom-contexts)

This 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 &amp; setter for the `ApiClient` instance.

ContextServiceExtension Integration
-----------------------------------

[](#contextserviceextension-integration)

If using the FriendsOfBehat [ContextServiceExtension](https://github.com/FriendsOfBehat/ContextServiceExtension), declare the `ApiContext` service like so:

```
services:
    # ...
    Persata\SymfonyApiExtension\Context\ApiContext:
        tags:
            - { name: fob.context_service }
```

If you need additional context services with access to the same shared ApiClient instance, have them extend `RawApiContext` and then declare the service like so:

```
services:
    # ...
    TheClass\Of\Your\CustomContext:
        tags:
            - { name: fob.context_service }
```

FOSRest Form Validation
-----------------------

[](#fosrest-form-validation)

If 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:

```
Then the JSON response should have the error "This value should not be null." at "user.firstName"
And the JSON response should not have any errors on "user.lastName"
```

Example Scenario
----------------

[](#example-scenario)

```
Scenario: Testing Basic JSON Endpoint
    Given the "Authorization" request header is "Bearer MyToken"
    When the request is sent using GET to "/example-endpoint"
    Then the response status code should be 200
    And the response content type should be JSON
    And the response content should be valid JSON
    And the JSON response should be
    """
    {
        "hello": "world"
    }
    """
    And the JSON response should have the structure
    """
    [
        "hello"
    ]
    """
```

Extension Configuration
-----------------------

[](#extension-configuration)

```
# behat.yml
default:
    extensions:
        Persata\SymfonyApiExtension:
            base_url: 'http://my-api.local' # Base URL used for requests sent to the Symfony kernel. Defaults to null.
            files_path: "%paths.base%/src/Behat/Resources/fixtures/" # Base directory of files to be used for upload tests. Defaults to null.
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Recently: every ~47 days

Total

17

Last Release

2834d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8840ec618d68385242a4fd00c26616015562cca796fe105e97fa70fd56eff5e0?d=identicon)[persata](/maintainers/persata)

---

Top Contributors

[![Persata](https://avatars.githubusercontent.com/u/1608834?v=4)](https://github.com/Persata "Persata (35 commits)")[![aeacusvol](https://avatars.githubusercontent.com/u/1385972?v=4)](https://github.com/aeacusvol "aeacusvol (2 commits)")

---

Tags

apibehatbehat-extensionsymfony

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/persata-symfony-api-extension/health.svg)

```
[![Health](https://phpackages.com/badges/persata-symfony-api-extension/health.svg)](https://phpackages.com/packages/persata-symfony-api-extension)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M650](/packages/sylius-sylius)[gheb/docusign-bundle

Symfony Bundle for electronic document signature with Docusign

3520.8k](/packages/gheb-docusign-bundle)[components-web-app/api-components-bundle

Creates a flexible API for a website's structure, reusable components and common functionality.

322.8k](/packages/components-web-app-api-components-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
