Skip to content
This repository was archived by the owner on Jan 27, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions PhdApiTestBundle.php

This file was deleted.

28 changes: 13 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
PhdApiTestBundle
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://img.shields.io/github/actions/workflow/status/phphd/api-test-bundle/ci.yaml?branch=main)](https://github.com/phphd/api-test-bundle/actions?query=branch%3Amain)
[![Codecov](https://codecov.io/gh/phphd/api-test-bundle/graph/badge.svg?token=GZRXWYT55Z)](https://codecov.io/gh/phphd/api-test-bundle)
[![Psalm coverage](https://shepherd.dev/github/phphd/api-test-bundle/coverage.svg)](https://shepherd.dev/github/phphd/api-test-bundle)
[![Psalm level](https://shepherd.dev/github/phphd/api-test-bundle/level.svg)](https://shepherd.dev/github/phphd/api-test-bundle)
[![Total Downloads](https://img.shields.io/packagist/dt/phphd/api-test-bundle.svg?style=flat-square)](https://packagist.org/packages/phphd/api-test-bundle)
[![Licence](https://img.shields.io/github/license/phphd/api-test-bundle.svg)](https://github.com/phphd/api-test-bundle/blob/main/LICENSE)
[![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)
[![Codecov](https://codecov.io/gh/phphd/api-testing/graph/badge.svg?token=GZRXWYT55Z)](https://codecov.io/gh/phphd/api-testing)
[![Psalm coverage](https://shepherd.dev/github/phphd/api-testing/coverage.svg)](https://shepherd.dev/github/phphd/api-testing)
[![Psalm level](https://shepherd.dev/github/phphd/api-testing/level.svg)](https://shepherd.dev/github/phphd/api-testing)
[![Total Downloads](https://img.shields.io/packagist/dt/phphd/api-testing.svg?style=flat-square)](https://packagist.org/packages/phphd/api-testing)
[![Licence](https://img.shields.io/github/license/phphd/api-testing.svg)](https://github.com/phphd/api-testing/blob/main/LICENSE)

## Quick Start

Expand All @@ -19,23 +19,23 @@ Cases.
1. Install via composer

```sh
composer require --dev phphd/api-test-bundle
composer require --dev phphd/api-testing
```

2. Enable the bundle in the `bundles.php`

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

### Configuration ⚒️

Create `phd_api_test.yaml` configuration file under `config/packages/test` directory. It's necessary to specify
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.

```yaml
phd_api_test:
phd_api_testing:
jwt_authenticators:
- name: default
user_provider: security.user_providers
Expand All @@ -46,9 +46,7 @@ phd_api_test:
In your Api Test class use `JwtLoginTrait` and `login` method to handle authentication:

```php
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;
use ApiPlatform\Symfony\Bundle\Test\Client;
use PhPhD\ApiTest\JwtLoginTrait;
use ApiPlatform\Symfony\Bundle\Test\ApiTestCase;use ApiPlatform\Symfony\Bundle\Test\Client;use PhPhD\ApiTesting\Jwt\JwtLoginTrait;

final class ExampleProtectedApiTest extends ApiTestCase
{
Expand Down Expand Up @@ -87,7 +85,7 @@ Nonetheless, in case of conflicting usernames or any other specific reason, you
in the same configuration file by different name:

```yaml
phd_api_test:
phd_api_testing:
jwt_authenticators:
- name: admin
user_provider: security.user.provider.concrete.api_admin_user_provider
Expand Down
20 changes: 11 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "phphd/api-test-bundle",
"name": "phphd/api-testing",
"description": "JWT Authentication for API testing",
"type": "library",
"license": "MIT",
Expand All @@ -18,21 +18,24 @@
"minimum-stability": "stable",
"require": {
"php": ">=8.1",
"symfony/http-kernel": "^6.0 | ^7.0",
"symfony/dependency-injection": "^6.1 | ^7.0",
"symfony/security-core": "^6.0 | ^7.0",
"lexik/jwt-authentication-bundle": "^2.0 | ^3.0"
"lexik/jwt-authentication-bundle": "^2.0 || ^3.0"
},
"require-dev": {
"symfony/var-dumper": "^6.0",
"phpstan/phpstan": "^1.10",
"vimeo/psalm": "^5.16",
"psalm/plugin-phpunit": "^0.18.4",
"phphd/coding-standard": "~0.5.1",
"phphd/coding-standard": "~0.5.3",
"phpunit/phpunit": "^9.4",
"phpstan/phpstan-phpunit": "^1.3",
"tomasvotruba/type-coverage": "^0.2.1"
},
"conflict": {
"symfony/http-kernel": "<6.0 || >=8.0",
"symfony/dependency-injection": "<6.1 || >=8.0",
"symfony/config": "<6.0 || >=8.0",
"symfony/security-core": "<6.0 || >=8.0"
},
"repositories": [
{
"type": "vcs",
Expand All @@ -41,16 +44,15 @@
],
"autoload": {
"psr-4": {
"PhPhD\\ApiTestBundle\\": "",
"PhPhD\\ApiTest\\": "src/"
"PhPhD\\ApiTesting\\": "src/"
},
"exclude-from-classmap": [
"/tests/"
]
},
"autoload-dev": {
"psr-4": {
"PhPhD\\ApiTest\\Tests\\": "tests/"
"PhPhD\\ApiTesting\\Tests\\": "tests/"
},
"files": [
"tests/aliases.php"
Expand Down
2 changes: 1 addition & 1 deletion ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

$ecsConfig->skip([
MethodChainingIndentationFixer::class => [
__DIR__.'/DependencyInjection/Configuration.php',
__DIR__.'/src/Bundle/DependencyInjection/Configuration.php',
],
]);
};
4 changes: 2 additions & 2 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
findUnusedCode="true"
>
<projectFiles>
<directory name="./"/>
<file name="PhdApiTestBundle.php"/>
<directory name="src"/>
<directory name="tests"/>
<ignoreFiles>
<directory name="vendor"/>
</ignoreFiles>
Expand Down
3 changes: 1 addition & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([PhdSetList::rector()->getPath()]);

$rectorConfig->paths([__DIR__.'/']);
$rectorConfig->skip([__DIR__.'/vendor']);
$rectorConfig->paths([__DIR__.'/src', __DIR__.'/tests']);

$rectorConfig->phpVersion(PhpVersion::PHP_80);
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PhPhD\ApiTestBundle\DependencyInjection;
namespace PhPhD\ApiTesting\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\Builder\NodeDefinition;
Expand All @@ -13,7 +13,7 @@ final class Configuration implements ConfigurationInterface
{
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(PhdApiTestExtension::ALIAS);
$treeBuilder = new TreeBuilder(PhdApiTestingExtension::ALIAS);

/** @var ArrayNodeDefinition $rootNode */
$rootNode = $treeBuilder->getRootNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

declare(strict_types=1);

namespace PhPhD\ApiTestBundle\DependencyInjection;
namespace PhPhD\ApiTesting\Bundle\DependencyInjection;

use Exception;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\AbstractExtension;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

final class PhdApiTestExtension extends AbstractExtension
final class PhdApiTestingExtension extends AbstractExtension
{
public const ALIAS = 'phd_api_test';
public const ALIAS = 'phd_api_testing';

/**
* @psalm-suppress MoreSpecificImplementedParamType
Expand All @@ -25,7 +25,7 @@ final class PhdApiTestExtension extends AbstractExtension
*/
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
{
$builder->setParameter('phd_api_test.config.jwt_authenticators', $config['jwt_authenticators']);
$builder->setParameter('phd_api_testing.config.jwt_authenticators', $config['jwt_authenticators']);

$container->import(__DIR__.'/../Resources/config/services.php');
}
Expand Down
18 changes: 18 additions & 0 deletions src/Bundle/PhdApiTestingBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace PhPhD\ApiTesting\Bundle;

use PhPhD\ApiTesting\Bundle\DependencyInjection\PhdApiTestingExtension;
use Symfony\Component\HttpKernel\Bundle\Bundle;

/** @api */
final class PhdApiTestingBundle extends Bundle
{
/** @override */
protected function createContainerExtension(): PhdApiTestingExtension
{
return new PhdApiTestingExtension();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use PhPhD\ApiTest\Authenticator\TestJwtAuthenticator;
use PhPhD\ApiTesting\Jwt\TestJwtAuthenticator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

Expand All @@ -12,11 +12,11 @@
$services = $container->services();

/** @var array<string,array{user_provider:string}> $authenticatorsConfig */
$authenticatorsConfig = $builder->getParameter('phd_api_test.config.jwt_authenticators');
$authenticatorsConfig = $builder->getParameter('phd_api_testing.config.jwt_authenticators');

foreach ($authenticatorsConfig as $name => $authenticator) {
$services
->set('phd_api_test.jwt_authenticator.'.$name, TestJwtAuthenticator::class)
->set('phd_api_testing.jwt_authenticator.'.$name, TestJwtAuthenticator::class)
->public()
->args([
service($authenticator['user_provider']),
Expand Down
5 changes: 2 additions & 3 deletions src/JwtLoginTrait.php → src/Jwt/JwtLoginTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

declare(strict_types=1);

namespace PhPhD\ApiTest;
namespace PhPhD\ApiTesting\Jwt;

use PhPhD\ApiTest\Authenticator\TestJwtAuthenticator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;

Expand All @@ -17,7 +16,7 @@ private function login(string $userId, string $authenticator = 'default'): strin
$container = self::getContainer();

/** @var TestJwtAuthenticator $testAuthenticator */
$testAuthenticator = $container->get('phd_api_test.jwt_authenticator.'.$authenticator);
$testAuthenticator = $container->get('phd_api_testing.jwt_authenticator.'.$authenticator);

return $testAuthenticator->authenticateUser($userId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PhPhD\ApiTest\Authenticator;
namespace PhPhD\ApiTesting\Jwt;

use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down
14 changes: 7 additions & 7 deletions tests/Unit/JwtLoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

declare(strict_types=1);

namespace PhPhD\ApiTest\Tests\Unit;
namespace PhPhD\ApiTesting\Tests\Unit;

use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use PhPhD\ApiTest\Authenticator\TestJwtAuthenticator;
use PhPhD\ApiTest\JwtLoginTrait;
use PhPhD\ApiTesting\Jwt\JwtLoginTrait;
use PhPhD\ApiTesting\Jwt\TestJwtAuthenticator;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;

/**
* @covers \PhPhD\ApiTest\JwtLoginTrait
* @covers \PhPhD\ApiTest\Authenticator\TestJwtAuthenticator
* @covers \PhPhD\ApiTesting\Jwt\JwtLoginTrait
* @covers \PhPhD\ApiTesting\Jwt\TestJwtAuthenticator
*
* @internal
*/
Expand Down Expand Up @@ -56,12 +56,12 @@ protected function setUp(): void
->method('get')
->willReturnMap([
[
'phd_api_test.jwt_authenticator.admin',
'phd_api_testing.jwt_authenticator.admin',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
new TestJwtAuthenticator($adminUserProvider, $tokenManager),
],
[
'phd_api_test.jwt_authenticator.default',
'phd_api_testing.jwt_authenticator.default',
ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE,
new TestJwtAuthenticator($ordinaryUserProvider, $tokenManager),
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Stub/Outlet/KernelTestCaseStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace PhPhD\ApiTest\Tests\Unit\Stub\Outlet;
namespace PhPhD\ApiTesting\Tests\Unit\Stub\Outlet;

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down
2 changes: 1 addition & 1 deletion tests/aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use PhPhD\ApiTest\Tests\Unit\Stub\Outlet\KernelTestCaseStub;
use PhPhD\ApiTesting\Tests\Unit\Stub\Outlet\KernelTestCaseStub;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

\class_alias(KernelTestCaseStub::class, KernelTestCase::class);