PHPackages                             eerison/pest-plugin-api-platform - 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. [Framework](/categories/framework)
4. /
5. eerison/pest-plugin-api-platform

AbandonedArchivedLibrary[Framework](/categories/framework)

eerison/pest-plugin-api-platform
================================

Pest plugin for Api platform

v1.1.0(4y ago)9194[1 PRs](https://github.com/eerison/pest-plugin-api-platform/pulls)MITPHPPHP ^7.4 || ^8.0

Since Aug 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/eerison/pest-plugin-api-platform)[ Packagist](https://packagist.org/packages/eerison/pest-plugin-api-platform)[ RSS](/packages/eerison-pest-plugin-api-platform/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (10)Used By (0)

Api platform for Pest
=====================

[](#api-platform-for-pest)

This package adds [Api platform](https://api-platform.com/) testing capabilities to **[Pest](https://pestphp.com)**.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require eerison/pest-plugin-api-platform --dev
```

Add `uses(ApiTestCase::class)` in your `tests/Pest.php`

```
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase;

uses(ApiTestCase::class)->beforeEach(fn() => static::bootKernel())->in('Feature');
```

Usage
-----

[](#usage)

```
it('is checking the body structure')
    ->group('response')
    ->get('/foo/response/200')
    ->expectResponseContent()
        ->json()
        ->toHaveKey('name', 'Erison')
        ->toHaveKey('company.name', 'Fake company');
```

or you can use importing the function

```
use function Eerison\PestPluginApiPlatform\get;

it('is checking the body structure using context.', function () {
    $responseContent = get('/foo/response/200')->getContent();

    expect($responseContent)
        ->json()
        ->toHaveKey('company.address')
    ;
});
```

using `findIriBy`

```
use function Eerison\PestPluginApiPlatform\{get, findIriBy};

it('can use findIriBy', function () {
    $iri = findIriBy(YourEntity::class, ['yourField' => 'yourValue']);
    $responseContent = get($iri)->getContent();

    expect($responseContent)
        ->json()
        ->toHaveKey('company.address')
    ;
});
```

using snapshot (please install [pest-plugin-snapshots](https://github.com/spatie/pest-plugin-snapshots#installation))

```
it('can be used with snapshot')
    ->group('response')
    ->get('/foo/response/200')
    ->expectResponseContent()
    ->json()
    ->toMatchJsonSnapshot();
```

Converting api platform test in pest
------------------------------------

[](#converting-api-platform-test-in-pest)

Before

```
