From 558e259b846360123440a807daa570354f1840bd Mon Sep 17 00:00:00 2001
From: Alejandro Celaya <alejandro@alejandrocelaya.com>
Date: Sun, 27 Jan 2019 10:30:38 +0100
Subject: [PATCH] Minor refactorings

---
 composer.json                                          | 1 +
 config/test/bootstrap_db_tests.php                     | 2 +-
 module/Common/test-db/ApiTest/ApiTestCase.php          | 5 ++++-
 module/Common/test-db/DbTest/DatabaseTestCase.php      | 9 +++++++--
 module/Rest/test-api/Middleware/AuthenticationTest.php | 2 +-
 5 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/composer.json b/composer.json
index fe118ee4..2e20ed83 100644
--- a/composer.json
+++ b/composer.json
@@ -141,6 +141,7 @@
         "test:unit": "<fg=blue;options=bold>Runs unit test suites</>",
         "test:unit:ci": "<fg=blue;options=bold>Runs unit test suites, generating all needed reports and logs for CI envs</>",
         "test:db": "<fg=blue;options=bold>Runs database test suites (covering entity repositories)</>",
+        "test:api": "<fg=blue;options=bold>Runs API test suites</>",
         "test:pretty": "<fg=blue;options=bold>Runs all test suites and generates an HTML code coverage report</>",
         "test:unit:pretty": "<fg=blue;options=bold>Runs unit test suites and generates an HTML code coverage report</>",
         "infect": "<fg=blue;options=bold>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');
     }
 }