Reset features controller cache in integration tests

[MAILPOET-4207]
This commit is contained in:
Jan Jakes
2022-03-31 14:31:17 +02:00
committed by Veljko V
parent 8a604e3743
commit 47a234c18e
2 changed files with 10 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ class FeaturesController {
self::AUTOMATION => false,
];
/** @var array */
/** @var array|null */
private $flags;
/** @var FeatureFlagsRepository */
@@ -36,7 +36,7 @@ class FeaturesController {
} catch (TableNotFoundException $e) {
return $this->defaults[$feature];
}
return $this->flags[$feature];
return ($this->flags ?? [])[$feature];
}
/** @return bool */
@@ -52,7 +52,11 @@ class FeaturesController {
/** @return array */
public function getAllFlags() {
$this->ensureFlagsLoaded();
return $this->flags;
return $this->flags ?? [];
}
public function resetCache(): void {
$this->flags = null;
}
private function ensureFlagsLoaded() {

View File

@@ -3,6 +3,7 @@
use MailPoet\Cache\TransientCache;
use MailPoet\DI\ContainerWrapper;
use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Features\FeaturesController;
use MailPoet\Settings\SettingsController;
use MailPoetVendor\Doctrine\DBAL\Connection;
use MailPoetVendor\Doctrine\ORM\EntityManager;
@@ -122,7 +123,9 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore
$this->diContainer = ContainerWrapper::getInstance(WP_DEBUG);
$this->connection = $this->diContainer->get(Connection::class);
$this->entityManager = $this->diContainer->get(EntityManager::class);
$this->diContainer->get(FeaturesController::class)->resetCache();
$this->diContainer->get(SettingsController::class)->resetCache();
// Cleanup scheduled tasks from previous tests
$this->truncateEntity(ScheduledTaskEntity::class);
$this->entityManager->clear();