Skip to content

Commit

Permalink
Merge pull request #212 from dotkernel/issue-211
Browse files Browse the repository at this point in the history
Throw exception if in-memory database when running tests
  • Loading branch information
arhimede committed Nov 6, 2023
2 parents 2e5c0f1 + 9803c56 commit 5520c60
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/Functional/AbstractFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,6 +55,8 @@ public function setUp(): void
$this->initPipeline();
$this->initRoutes();

$this->ensureTestMode();

if (method_exists($this, 'runMigrations')) {
$this->runMigrations();
}
Expand Down Expand Up @@ -132,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 = [],
Expand Down

0 comments on commit 5520c60

Please sign in to comment.