{"id":20314957,"url":"https://github.com/phphd/api-testing","last_synced_at":"2026-01-05T22:42:59.721Z","repository":{"id":205847208,"uuid":"713552814","full_name":"phphd/api-testing","owner":"phphd","description":"JWT Authentication for API testing in Symfony applications","archived":false,"fork":false,"pushed_at":"2024-09-16T11:25:12.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-30T15:10:27.117Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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/phphd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2023-11-02T18:51:24.000Z","updated_at":"2024-09-16T10:57:14.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec507b1b-d1bc-4883-a16b-21fc74ce0264","html_url":"https://github.com/phphd/api-testing","commit_stats":null,"previous_names":["phphd/jwt-auth-test-bundle","phphd/api-test-bundle","phphd/api-testing"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/phphd/api-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphd%2Fapi-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphd%2Fapi-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphd%2Fapi-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphd%2Fapi-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phphd","download_url":"https://codeload.github.com/phphd/api-testing/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phphd%2Fapi-testing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28219090,"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","status":"online","status_checked_at":"2026-01-05T02:00:06.358Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2024-11-14T18:17:24.346Z","updated_at":"2026-01-05T22:42:59.701Z","avatar_url":"https://github.com/phphd.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"PhdApiTestingBundle\n--------------------\n\n🧰 Provides lightweight jwt authorization utilities for Api Testing in Symfony applications. In essence, this package\nintegrates [Lexik JWT Authentication Bundle](https://github.com/lexik/LexikJWTAuthenticationBundle) into your Api Test\nCases.\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/phphd/api-testing/ci.yaml?branch=main)](https://github.com/phphd/api-testing/actions?query=branch%3Amain)\n[![Codecov](https://codecov.io/gh/phphd/api-testing/graph/badge.svg?token=GZRXWYT55Z)](https://codecov.io/gh/phphd/api-testing)\n[![Psalm coverage](https://shepherd.dev/github/phphd/api-testing/coverage.svg)](https://shepherd.dev/github/phphd/api-testing)\n[![Psalm level](https://shepherd.dev/github/phphd/api-testing/level.svg)](https://shepherd.dev/github/phphd/api-testing)\n[![Total Downloads](https://img.shields.io/packagist/dt/phphd/api-testing.svg?style=flat-square)](https://packagist.org/packages/phphd/api-testing)\n[![Licence](https://img.shields.io/github/license/phphd/api-testing.svg)](https://github.com/phphd/api-testing/blob/main/LICENSE)\n\n## Quick Start\n\n### Installation 📥\n\n1. Install via composer\n\n    ```sh\n    composer require --dev phphd/api-testing\n    ```\n\n2. Enable the bundle in the `bundles.php`\n\n    ```php\n    PhPhD\\ApiTesting\\Bundle\\PhdApiTestingBundle::class =\u003e ['test' =\u003e true],\n    ```\n\n### Configuration ⚒️\n\nCreate `phd_api_testing.yaml` configuration file under `config/packages/test` directory. It's necessary to specify\nservice id of application [user provider](https://symfony.com/doc/current/security/user_providers.html) here. If you\nhave only one authenticated user entity (hence, one provider), use current default configuration.\n\n```yaml\nphd_api_testing:\n    jwt_authenticators:\n        -   name: default\n            user_provider: security.user_providers\n```\n\n### Usage 🚀\n\nIn your Api Test class use `JwtLoginTrait` and `login` method to handle authentication:\n\n```php\nuse PhPhD\\ApiTesting\\Jwt\\JwtLoginTrait;\n\nfinal class ExampleProtectedApiTest extends ApiTestCase\n{\n    use JwtLoginTrait;\n    \n    // ...\n\n    public function testAccessFeatureWithoutPassword(): void\n    {\n        $token = $this-\u003elogin('username');\n\n        $this-\u003eclient-\u003erequest('GET', '/api/protected-route', [\n            'auth_bearer' =\u003e $token,\n        ]);\n\n        self::assertResponseStatusCodeSame(200);\n    }\n}\n```\n\nIn this example, `login` is used to generate jwt token for `username` user so that api request will be sent on his\nbehalf.\n\n## Advanced Configuration ⚙️\n\n### Multiple Authenticators\n\nIt is possible to use multiple authenticators for your specific needs. For instance if you have admin panel alongside\nyour main authenticated application, you may want to use the dedicated authenticator.\n\nIn essence, if you're utilizing `security.user_providers`, additional configuration is typically unnecessary,\nsince `security.user_providers` acts as a chain user provider, meaning that first found user from any subordinate\nproviders will be used.\n\nNonetheless, in case of conflicting usernames or any other specific reason, you may register an additional authenticator\nin the same configuration file by different name:\n\n```yaml\nphd_api_testing:\n    jwt_authenticators:\n        -   name: admin\n            user_provider: security.user.provider.concrete.api_admin_user_provider\n```\n\nIn this config, `api_admin_user_provider` is the name of user provider from `security.yaml` and `admin` - just an alias\nfor our usage in tests.\n\nHaving registered authenticator, we may use its alias as a second parameter of `login` method:\n\n```php\npublic function testDedicatedAdminAuthenticator(): void\n{\n    $token = $this-\u003elogin('admin@test.com', authenticator: 'admin');\n\n    $this-\u003eclient-\u003erequest('GET', '/api/admin/protected-route', [\n        'auth_bearer' =\u003e $token,\n    ]);\n\n    self::assertResponseStatusCodeSame(200);\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphphd%2Fapi-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphphd%2Fapi-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphphd%2Fapi-testing/lists"}