AzuraCast/src/Tests/Module.php

82 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2021-07-19 07:53:45 +02:00
declare(strict_types=1);
/**
* 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;
use App\Doctrine\ReloadableEntityManagerInterface;
2022-01-17 05:45:07 +01:00
use App\Enums\ApplicationEnvironment;
use App\Environment;
use Codeception\Configuration;
use Codeception\Lib\Framework;
use Codeception\Lib\Interfaces\DoctrineProvider;
2021-07-19 07:53:45 +02:00
use Codeception\Lib\ModuleContainer;
use Codeception\TestInterface;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Container\ContainerInterface;
2021-12-11 04:48:19 +01:00
use RuntimeException;
use Slim\App;
class Module extends Framework implements DoctrineProvider
{
public ContainerInterface $container;
public App $app;
public ReloadableEntityManagerInterface $em;
public function __construct(ModuleContainer $moduleContainer, ?array $config = null)
2021-07-19 07:53:45 +02:00
{
parent::__construct($moduleContainer, $config);
$this->requiredFields = ['container'];
}
2021-06-08 08:40:49 +02:00
public function _initialize(): void
{
2022-05-08 20:05:02 +02:00
$this->app = AppFactory::createApp(
[
Environment::BASE_DIR => Configuration::projectDir(),
2022-05-08 20:05:02 +02:00
Environment::APP_ENV => ApplicationEnvironment::Testing->value,
]
);
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;
$this->em = $this->container->get(ReloadableEntityManagerInterface::class);
parent::_initialize();
}
2021-06-08 08:40:49 +02:00
public function _before(TestInterface $test): void
{
$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
{
$_GET = [];
$_POST = [];
$_COOKIE = [];
parent::_after($test);
}
2020-07-09 04:32:34 +02:00
public function _getEntityManager(): EntityManagerInterface
{
return $this->em;
}
}