2020-02-06 03:35:13 +01:00
|
|
|
<?php
|
2021-07-19 07:53:45 +02:00
|
|
|
declare(strict_types=1);
|
2020-10-15 00:19:31 +02:00
|
|
|
|
2020-02-06 03:35:13 +01:00
|
|
|
/**
|
|
|
|
* Based on Herloct's Slim 3.0 Connector
|
|
|
|
* https://github.com/herloct/codeception-slim-module
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Tests;
|
|
|
|
|
2022-05-08 20:05:02 +02:00
|
|
|
use App\AppFactory;
|
2021-06-14 06:49:17 +02:00
|
|
|
use App\Doctrine\ReloadableEntityManagerInterface;
|
2022-01-17 05:45:07 +01:00
|
|
|
use App\Enums\ApplicationEnvironment;
|
2020-12-03 05:18:06 +01:00
|
|
|
use App\Environment;
|
2020-02-06 03:35:13 +01:00
|
|
|
use Codeception\Configuration;
|
|
|
|
use Codeception\Lib\Framework;
|
|
|
|
use Codeception\Lib\Interfaces\DoctrineProvider;
|
2021-07-19 07:53:45 +02:00
|
|
|
use Codeception\Lib\ModuleContainer;
|
2020-02-06 03:35:13 +01:00
|
|
|
use Codeception\TestInterface;
|
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
use Psr\Container\ContainerInterface;
|
2021-12-11 04:48:19 +01:00
|
|
|
use RuntimeException;
|
2020-02-06 03:35:13 +01:00
|
|
|
use Slim\App;
|
|
|
|
|
|
|
|
class Module extends Framework implements DoctrineProvider
|
|
|
|
{
|
2020-06-26 22:22:53 +02:00
|
|
|
public ContainerInterface $container;
|
2020-02-06 03:35:13 +01:00
|
|
|
|
2020-06-26 22:22:53 +02:00
|
|
|
public App $app;
|
2020-02-06 03:35:13 +01:00
|
|
|
|
2021-06-14 06:49:17 +02:00
|
|
|
public ReloadableEntityManagerInterface $em;
|
2020-02-06 03:35:13 +01:00
|
|
|
|
2022-03-17 01:04:40 +01:00
|
|
|
public function __construct(ModuleContainer $moduleContainer, ?array $config = null)
|
2021-07-19 07:53:45 +02:00
|
|
|
{
|
|
|
|
parent::__construct($moduleContainer, $config);
|
|
|
|
|
|
|
|
$this->requiredFields = ['container'];
|
|
|
|
}
|
2020-02-06 03:35:13 +01:00
|
|
|
|
2021-06-08 08:40:49 +02:00
|
|
|
public function _initialize(): void
|
2020-02-06 03:35:13 +01:00
|
|
|
{
|
2022-05-08 20:05:02 +02:00
|
|
|
$this->app = AppFactory::createApp(
|
2021-03-11 06:58:39 +01:00
|
|
|
[
|
|
|
|
Environment::BASE_DIR => Configuration::projectDir(),
|
2022-05-08 20:05:02 +02:00
|
|
|
Environment::APP_ENV => ApplicationEnvironment::Testing->value,
|
2021-03-11 06:58:39 +01:00
|
|
|
]
|
|
|
|
);
|
2020-02-06 03:35:13 +01:00
|
|
|
|
2021-07-19 07:53:45 +02:00
|
|
|
$container = $this->app->getContainer();
|
|
|
|
if (null === $container) {
|
2021-12-11 04:48:19 +01:00
|
|
|
throw new RuntimeException('Container was not set on App.');
|
2021-07-19 07:53:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->container = $container;
|
2021-06-14 06:49:17 +02:00
|
|
|
$this->em = $this->container->get(ReloadableEntityManagerInterface::class);
|
2020-02-06 03:35:13 +01:00
|
|
|
|
|
|
|
parent::_initialize();
|
|
|
|
}
|
|
|
|
|
2021-06-08 08:40:49 +02:00
|
|
|
public function _before(TestInterface $test): void
|
2020-02-06 03:35:13 +01:00
|
|
|
{
|
|
|
|
$this->client = new Connector();
|
|
|
|
$this->client->setApp($this->app);
|
|
|
|
|
|
|
|
parent::_before($test);
|
|
|
|
}
|
|
|
|
|
2021-06-08 08:40:49 +02:00
|
|
|
public function _after(TestInterface $test): void
|
2020-02-06 03:35:13 +01:00
|
|
|
{
|
|
|
|
$_GET = [];
|
|
|
|
$_POST = [];
|
|
|
|
$_COOKIE = [];
|
|
|
|
|
|
|
|
parent::_after($test);
|
|
|
|
}
|
2020-07-09 04:32:34 +02:00
|
|
|
|
2020-06-26 22:22:53 +02:00
|
|
|
public function _getEntityManager(): EntityManagerInterface
|
2020-02-06 03:35:13 +01:00
|
|
|
{
|
|
|
|
return $this->em;
|
|
|
|
}
|
|
|
|
}
|