diff --git a/composer.json b/composer.json index fe118ee4..2e20ed83 100644 --- a/composer.json +++ b/composer.json @@ -141,6 +141,7 @@ "test:unit": "Runs unit test suites", "test:unit:ci": "Runs unit test suites, generating all needed reports and logs for CI envs", "test:db": "Runs database test suites (covering entity repositories)", + "test:api": "Runs API test suites", "test:pretty": "Runs all test suites and generates an HTML code coverage report", "test:unit:pretty": "Runs unit test suites and generates an HTML code coverage report", "infect": "Checks unit tests quality applying mutation testing", diff --git a/config/test/bootstrap_db_tests.php b/config/test/bootstrap_db_tests.php index 2639d152..58bc2174 100644 --- a/config/test/bootstrap_db_tests.php +++ b/config/test/bootstrap_db_tests.php @@ -16,4 +16,4 @@ if (! file_exists('.env')) { $container = require __DIR__ . '/../container.php'; $container->get(TestHelper::class)->createTestDb(); -DbTest\DatabaseTestCase::$em = $container->get('em'); +DbTest\DatabaseTestCase::setEntityManager($container->get('em')); diff --git a/module/Common/test-db/ApiTest/ApiTestCase.php b/module/Common/test-db/ApiTest/ApiTestCase.php index 0a190822..1aae1065 100644 --- a/module/Common/test-db/ApiTest/ApiTestCase.php +++ b/module/Common/test-db/ApiTest/ApiTestCase.php @@ -8,9 +8,12 @@ use Fig\Http\Message\StatusCodeInterface; use GuzzleHttp\ClientInterface; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; +use function sprintf; abstract class ApiTestCase extends TestCase implements StatusCodeInterface, RequestMethodInterface { + private const PATH_PREFX = '/rest/v1'; + /** @var ClientInterface */ private static $client; @@ -24,6 +27,6 @@ abstract class ApiTestCase extends TestCase implements StatusCodeInterface, Requ */ protected function callApi(string $method, string $uri, array $options = []): ResponseInterface { - return self::$client->request($method, $uri, $options); + return self::$client->request($method, sprintf('%s%s', self::PATH_PREFX, $uri), $options); } } diff --git a/module/Common/test-db/DbTest/DatabaseTestCase.php b/module/Common/test-db/DbTest/DatabaseTestCase.php index ba8b031d..dc102c8c 100644 --- a/module/Common/test-db/DbTest/DatabaseTestCase.php +++ b/module/Common/test-db/DbTest/DatabaseTestCase.php @@ -11,11 +11,16 @@ abstract class DatabaseTestCase extends TestCase protected const ENTITIES_TO_EMPTY = []; /** @var EntityManagerInterface */ - public static $em; + private static $em; + + public static function setEntityManager(EntityManagerInterface $em): void + { + self::$em = $em; + } protected function getEntityManager(): EntityManagerInterface { - return static::$em; + return self::$em; } public function tearDown() diff --git a/module/Rest/test-api/Middleware/AuthenticationTest.php b/module/Rest/test-api/Middleware/AuthenticationTest.php index dc6032fc..1b0d776e 100644 --- a/module/Rest/test-api/Middleware/AuthenticationTest.php +++ b/module/Rest/test-api/Middleware/AuthenticationTest.php @@ -16,6 +16,6 @@ class AuthenticationTest extends ApiTestCase $this->expectException(ClientException::class); $this->expectExceptionCode(self::STATUS_UNAUTHORIZED); - $this->callApi(self::METHOD_GET, '/rest/v1/short-codes'); + $this->callApi(self::METHOD_GET, '/short-codes'); } }