Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw exception if in-memory database when running tests #212

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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