2.0 RC 1 - new ConfigurationService (#3810)
* use html5 email validation * remove static cache seed, for compatibility with non default (file based) caches * added caching ConfigurationService, removed use of doctrine result cache * simplify configuration API
This commit is contained in:
@@ -18,29 +18,22 @@ use App\Entity\Configuration;
|
||||
class TestConfigLoader implements ConfigLoaderInterface
|
||||
{
|
||||
/**
|
||||
* @var Configuration[]
|
||||
* @var array<string, string|null>
|
||||
*/
|
||||
private array $configs;
|
||||
private array $configs = [];
|
||||
|
||||
/**
|
||||
* @param Configuration[] $configs
|
||||
*/
|
||||
public function __construct(array $configs)
|
||||
{
|
||||
$this->configs = $configs;
|
||||
}
|
||||
|
||||
public function getConfiguration(string $name): ?Configuration
|
||||
{
|
||||
if (!\array_key_exists($name, $this->configs)) {
|
||||
return null;
|
||||
foreach ($configs as $config) {
|
||||
$this->configs[$config->getName()] = $config->getValue();
|
||||
}
|
||||
|
||||
return $this->configs[$name];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Configuration[]
|
||||
* @return array<string, string|null>
|
||||
*/
|
||||
public function getConfigurations(): array
|
||||
{
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Configuration\ConfigurationService;
|
||||
use App\DataFixtures\UserFixtures;
|
||||
use App\Entity\Configuration;
|
||||
use App\Entity\User;
|
||||
use App\Form\Type\DateRangeType;
|
||||
use App\Repository\ConfigurationRepository;
|
||||
use App\Repository\UserRepository;
|
||||
use App\Tests\KernelTestTrait;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
@@ -89,9 +89,10 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
|
||||
protected function setSystemConfiguration(string $name, $value): void
|
||||
{
|
||||
$repository = self::getContainer()->get(ConfigurationRepository::class);
|
||||
/** @var ConfigurationService $repository */
|
||||
$repository = self::getContainer()->get(ConfigurationService::class);
|
||||
|
||||
$entity = $repository->findOneBy(['name' => $name]);
|
||||
$entity = $repository->getConfiguration($name);
|
||||
if ($entity === null) {
|
||||
$entity = new Configuration();
|
||||
$entity->setName($name);
|
||||
@@ -103,9 +104,9 @@ abstract class ControllerBaseTest extends WebTestCase
|
||||
|
||||
protected function clearConfigCache()
|
||||
{
|
||||
/** @var ConfigurationRepository $repository */
|
||||
$repository = self::getContainer()->get(ConfigurationRepository::class);
|
||||
$repository->clearCache();
|
||||
/** @var ConfigurationService $service */
|
||||
$service = self::getContainer()->get(ConfigurationService::class);
|
||||
$service->clearCache();
|
||||
}
|
||||
|
||||
protected function getClientForAuthenticatedUser(string $role = User::ROLE_USER): HttpKernelBrowser
|
||||
|
||||
@@ -10,11 +10,9 @@
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Configuration;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\TimesheetMeta;
|
||||
use App\Entity\User;
|
||||
use App\Repository\ConfigurationRepository;
|
||||
use App\Repository\TagRepository;
|
||||
use App\Tests\DataFixtures\ActivityFixtures;
|
||||
use App\Tests\DataFixtures\TagFixtures;
|
||||
@@ -442,12 +440,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
/** @var ConfigurationRepository $repository */
|
||||
$repository = $this->getEntityManager()->getRepository(Configuration::class);
|
||||
$config = new Configuration();
|
||||
$config->setName('timesheet.rules.allow_overbooking_budget');
|
||||
$config->setValue(false);
|
||||
$repository->saveConfiguration($config);
|
||||
$this->setSystemConfiguration('timesheet.rules.allow_overbooking_budget', false);
|
||||
|
||||
$this->assertHasValidationError(
|
||||
$client,
|
||||
@@ -496,12 +489,7 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$response = $client->getResponse();
|
||||
$this->assertTrue($response->isSuccessful());
|
||||
|
||||
/** @var ConfigurationRepository $repository */
|
||||
$repository = $this->getEntityManager()->getRepository(Configuration::class);
|
||||
$config = new Configuration();
|
||||
$config->setName('timesheet.rules.allow_zero_duration');
|
||||
$config->setValue(false);
|
||||
$repository->saveConfiguration($config);
|
||||
$this->setSystemConfiguration('timesheet.rules.allow_zero_duration', false);
|
||||
|
||||
$this->assertHasValidationError(
|
||||
$client,
|
||||
|
||||
@@ -2867,11 +2867,6 @@ parameters:
|
||||
count: 4
|
||||
path: Controller/CalendarControllerTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method findOneBy\\(\\) on object\\|null\\.$#"
|
||||
count: 1
|
||||
path: Controller/ControllerBaseTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method getRepository\\(\\) on object\\|null\\.$#"
|
||||
count: 1
|
||||
@@ -2887,11 +2882,6 @@ parameters:
|
||||
count: 1
|
||||
path: Controller/ControllerBaseTest.php
|
||||
|
||||
-
|
||||
message: "#^Cannot call method saveConfiguration\\(\\) on object\\|null\\.$#"
|
||||
count: 1
|
||||
path: Controller/ControllerBaseTest.php
|
||||
|
||||
-
|
||||
message: "#^Method App\\\\Tests\\\\Controller\\\\ControllerBaseTest\\:\\:assert404\\(\\) has no return type specified\\.$#"
|
||||
count: 1
|
||||
|
||||
Reference in New Issue
Block a user