From 777ac302e7d3e36bb1f8a542cce7c26e93f4afca Mon Sep 17 00:00:00 2001 From: MarioRadu Date: Fri, 3 Nov 2023 12:45:29 +0200 Subject: [PATCH 1/2] throw exception if in-memory database when running tests --- test/Functional/AbstractFunctionalTest.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Functional/AbstractFunctionalTest.php b/test/Functional/AbstractFunctionalTest.php index 8d40509..cdea483 100644 --- a/test/Functional/AbstractFunctionalTest.php +++ b/test/Functional/AbstractFunctionalTest.php @@ -25,6 +25,7 @@ use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; +use RuntimeException; use function array_merge; use function getenv; @@ -54,6 +55,12 @@ public function setUp(): void $this->initPipeline(); $this->initRoutes(); + if ($this->isTestMode() && ! $this->getEntityManager()->getConnection()->getParams()['memory']) { + throw new RuntimeException( + 'You are running tests in a non in-memory database. + Did you forgot to create the local.test.php file?' + ); + } if (method_exists($this, 'runMigrations')) { $this->runMigrations(); } From 9803c560eec7733f7f9c129bf9e8b2ffe071aac1 Mon Sep 17 00:00:00 2001 From: MarioRadu Date: Mon, 6 Nov 2023 11:20:27 +0200 Subject: [PATCH 2/2] requested changes --- test/Functional/AbstractFunctionalTest.php | 28 +++++++++++++++++----- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/test/Functional/AbstractFunctionalTest.php b/test/Functional/AbstractFunctionalTest.php index cdea483..debb5e2 100644 --- a/test/Functional/AbstractFunctionalTest.php +++ b/test/Functional/AbstractFunctionalTest.php @@ -55,12 +55,8 @@ public function setUp(): void $this->initPipeline(); $this->initRoutes(); - if ($this->isTestMode() && ! $this->getEntityManager()->getConnection()->getParams()['memory']) { - throw new RuntimeException( - 'You are running tests in a non in-memory database. - Did you forgot to create the local.test.php file?' - ); - } + $this->ensureTestMode(); + if (method_exists($this, 'runMigrations')) { $this->runMigrations(); } @@ -139,6 +135,26 @@ protected function getContainer(): ContainerInterface|ServiceManager return $this->container; } + /** + * @throws ContainerExceptionInterface + * @throws NotFoundExceptionInterface + * @throws RuntimeException + */ + private function ensureTestMode(): void + { + if (! $this->isTestMode()) { + throw new RuntimeException( + 'You are running tests, but test mode is NOT enabled. Did you forget to create local.test.php?' + ); + } + + if (! $this->getEntityManager()->getConnection()->getParams()['memory'] ?? false) { + throw new RuntimeException( + 'You are running tests in a non in-memory database. Did you forget to create local.test.php?' + ); + } + } + protected function get( string $uri, array $queryParams = [],