PHPackages                             phphd/api-test-bundle - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. phphd/api-test-bundle

Abandoned → [phphd/api-testing](/?search=phphd%2Fapi-testing)ArchivedLibrary[Testing &amp; Quality](/categories/testing)

phphd/api-test-bundle
=====================

JWT Authentication for API testing

1.1.0(1y ago)03.0kMITPHPPHP &gt;=8.1

Since Feb 5Pushed 1y agoCompare

[ Source](https://github.com/phphd/api-testing)[ Packagist](https://packagist.org/packages/phphd/api-test-bundle)[ RSS](/packages/phphd-api-test-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (9)Versions (5)Used By (0)

PhdApiTestingBundle
-------------------

[](#phdapitestingbundle)

🧰 Provides lightweight jwt authorization utilities for Api Testing in Symfony applications. In essence, this package integrates [Lexik JWT Authentication Bundle](https://github.com/lexik/LexikJWTAuthenticationBundle) into your Api Test Cases.

[![Build Status](https://camo.githubusercontent.com/562e2aca098a9496946d94c5df89b725142a7e3d13511b59d9311e91e7c80fbf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f70687068642f6170692d74657374696e672f63692e79616d6c3f6272616e63683d6d61696e)](https://github.com/phphd/api-testing/actions?query=branch%3Amain)[![Codecov](https://camo.githubusercontent.com/8ed0b7d0c70a4b7904da808b35060908db030709aa298e7fef6c9dcdbd09d94f/68747470733a2f2f636f6465636f762e696f2f67682f70687068642f6170692d74657374696e672f67726170682f62616467652e7376673f746f6b656e3d475a525857595435355a)](https://codecov.io/gh/phphd/api-testing)[![Psalm coverage](https://camo.githubusercontent.com/c00a997801d4dfef30540c8b193de38ac7b876f74ac1e4c7948b13e3320d43d7/68747470733a2f2f73686570686572642e6465762f6769746875622f70687068642f6170692d74657374696e672f636f7665726167652e737667)](https://shepherd.dev/github/phphd/api-testing)[![Psalm level](https://camo.githubusercontent.com/b6b453ce30cde21f3244f4b5954f1cdade7425721104fb1aa1d82bbda8044ada/68747470733a2f2f73686570686572642e6465762f6769746875622f70687068642f6170692d74657374696e672f6c6576656c2e737667)](https://shepherd.dev/github/phphd/api-testing)[![Total Downloads](https://camo.githubusercontent.com/43c3588df55755d38f3f912d57464d864d5893391a68c2d657ae7f977d6d15ef/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70687068642f6170692d74657374696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phphd/api-testing)[![Licence](https://camo.githubusercontent.com/c3eb471019a4687d5a247cec6c2c49a87ecc5fada2dffe934c140d1c66d54471/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70687068642f6170692d74657374696e672e737667)](https://github.com/phphd/api-testing/blob/main/LICENSE)

Quick Start
-----------

[](#quick-start)

### Installation 📥

[](#installation-)

1. Install via composer

    ```
    composer require --dev phphd/api-testing
    ```
2. Enable the bundle in the `bundles.php`

    ```
    PhPhD\ApiTesting\Bundle\PhdApiTestingBundle::class => ['test' => true],
    ```

### Configuration ⚒️

[](#configuration-️)

Create `phd_api_testing.yaml` configuration file under `config/packages/test` directory. It's necessary to specify service id of application [user provider](https://symfony.com/doc/current/security/user_providers.html) here. If you have only one authenticated user entity (hence, one provider), use current default configuration.

```
phd_api_testing:
    jwt_authenticators:
        -   name: default
            user_provider: security.user_providers
```

### Usage 🚀

[](#usage-)

In your Api Test class use `JwtLoginTrait` and `login` method to handle authentication:

```
use PhPhD\ApiTesting\Jwt\JwtLoginTrait;

final class ExampleProtectedApiTest extends ApiTestCase
{
    use JwtLoginTrait;

    // ...

    public function testAccessFeatureWithoutPassword(): void
    {
        $token = $this->login('username');

        $this->client->request('GET', '/api/protected-route', [
            'auth_bearer' => $token,
        ]);

        self::assertResponseStatusCodeSame(200);
    }
}
```

In this example, `login` is used to generate jwt token for `username` user so that api request will be sent on his behalf.

Advanced Configuration ⚙️
-------------------------

[](#advanced-configuration-️)

### Multiple Authenticators

[](#multiple-authenticators)

It is possible to use multiple authenticators for your specific needs. For instance if you have admin panel alongside your main authenticated application, you may want to use the dedicated authenticator.

In essence, if you're utilizing `security.user_providers`, additional configuration is typically unnecessary, since `security.user_providers` acts as a chain user provider, meaning that first found user from any subordinate providers will be used.

Nonetheless, in case of conflicting usernames or any other specific reason, you may register an additional authenticator in the same configuration file by different name:

```
phd_api_testing:
    jwt_authenticators:
        -   name: admin
            user_provider: security.user.provider.concrete.api_admin_user_provider
```

In this config, `api_admin_user_provider` is the name of user provider from `security.yaml` and `admin` - just an alias for our usage in tests.

Having registered authenticator, we may use its alias as a second parameter of `login` method:

```
public function testDedicatedAdminAuthenticator(): void
{
    $token = $this->login('admin@test.com', authenticator: 'admin');

    $this->client->request('GET', '/api/admin/protected-route', [
        'auth_bearer' => $token,
    ]);

    self::assertResponseStatusCodeSame(200);
}
```

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.1% 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 ~224 days

Total

2

Last Release

609d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/41589422?v=4)[Yevhen Sidelnyk](/maintainers/rela589n)[@rela589n](https://github.com/rela589n)

---

Top Contributors

[![rela589n](https://avatars.githubusercontent.com/u/41589422?v=4)](https://github.com/rela589n "rela589n (16 commits)")[![yevhen-sidelnyk-stfalcon](https://avatars.githubusercontent.com/u/254649937?v=4)](https://github.com/yevhen-sidelnyk-stfalcon "yevhen-sidelnyk-stfalcon (1 commits)")

---

Tags

jwttestingphpunitauth

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phphd-api-test-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/phphd-api-test-bundle/health.svg)](https://phpackages.com/packages/phphd-api-test-bundle)
```

###  Alternatives

[phpunit/phpunit

The PHP Unit Testing framework.

20.0k910.7M134.8k](/packages/phpunit-phpunit)[brianium/paratest

Parallel testing for PHP

2.5k118.8M754](/packages/brianium-paratest)[codedungeon/phpunit-result-printer

PHPUnit Pretty Result Printer

1.2k8.8M397](/packages/codedungeon-phpunit-result-printer)[spatie/phpunit-snapshot-assertions

Snapshot testing with PHPUnit

69617.9M510](/packages/spatie-phpunit-snapshot-assertions)[dg/bypass-finals

Removes final keyword from source code on-the-fly and allows mocking of final methods and classes

57026.3M456](/packages/dg-bypass-finals)[phpunit/phpunit-selenium

Selenium Server integration for PHPUnit

59610.9M150](/packages/phpunit-phpunit-selenium)

PHPackages © 2026

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