Minor refactorings

This commit is contained in:
Alejandro Celaya 2019-01-27 10:30:38 +01:00
parent f467bed24c
commit 558e259b84
5 changed files with 14 additions and 5 deletions

View file

@ -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</>",

View file

@ -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'));

View file

@ -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);
}
}

View file

@ -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()

View file

@ -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');
}
}