Skip to content

Commit

Permalink
TASK: Use FlowEntitiesTrait::truncateAndSetupFlowEntities to reset pe…
Browse files Browse the repository at this point in the history
…rsistence

Previously the doctrine entities would still exist of the previous test.
  • Loading branch information
mhsdesign committed Jun 21, 2024
1 parent 96bd529 commit 44c0f22
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
10 changes: 9 additions & 1 deletion Tests/Functional/AbstractNodeTemplateTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Flowpack\NodeTemplates\Domain\NodeTemplateDumper\NodeTemplateDumper;
use Flowpack\NodeTemplates\Domain\Template\RootTemplate;
use Flowpack\NodeTemplates\Domain\TemplateConfiguration\TemplateConfigurationProcessor;
use Neos\Behat\FlowEntitiesTrait;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode;
Expand Down Expand Up @@ -35,13 +36,14 @@
use Neos\Neos\Ui\TypeConverter\ChangeCollectionConverter;
use PHPUnit\Framework\TestCase;

abstract class AbstractNodeTemplateTestCase extends TestCase // we don't use Flows functional test case as it would reset the database afterwards
abstract class AbstractNodeTemplateTestCase extends TestCase // we don't use Flows functional test case as it would reset the database afterwards (see FlowEntitiesTrait)
{
use SnapshotTrait;
use FeedbackCollectionMessagesTrait;
use JsonSerializeNodeTreeTrait;
use WithConfigurationTrait;
use FakeNodeTypeManagerTrait;
use FlowEntitiesTrait;

use ContentRepositoryTestTrait;

Expand Down Expand Up @@ -91,6 +93,7 @@ public function tearDown(): void
private function setupContentRepository(): void
{
$this->initCleanContentRepository(ContentRepositoryId::fromString('node_templates'));
$this->truncateAndSetupFlowEntities();

$this->nodeTypeManager = $this->contentRepository->getNodeTypeManager();
$this->loadFakeNodeTypes();
Expand Down Expand Up @@ -242,4 +245,9 @@ protected function assertNodeDumpAndTemplateDumpMatchSnapshot(string $snapShotNa

$this->assertStringEqualsFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.yaml', $yamlTemplateWithoutOriginNodeTypeName);
}

final protected function getObject(string $className): object
{
return $this->objectManager->get($className);
}
}
34 changes: 12 additions & 22 deletions Tests/Functional/ContentRepositoryTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,37 @@
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\ObjectManagement\ObjectManager;
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
use Neos\Flow\ObjectManagement\ObjectManagerInterface;

/**
* @property ObjectManager $objectManager
*/
trait ContentRepositoryTestTrait
{
private readonly ContentRepository $contentRepository;

private readonly ContentRepositoryId $contentRepositoryId;

private static bool $persistenceWasSetup = false;

private static bool $wasContentRepositorySetupCalled = false;

/**
* @template T of object
* @param class-string<T> $className
*
* @return T
*/
abstract protected function getObject(string $className): object;

private function initCleanContentRepository(ContentRepositoryId $contentRepositoryId): void
{
if (!self::$persistenceWasSetup) {
// TODO super hacky and as we never clean up !!!
$persistenceManager = $this->objectManager->get(PersistenceManager::class);
if (is_callable([$persistenceManager, 'compile'])) {
$result = $persistenceManager->compile();
if ($result === false) {
self::markTestSkipped('Test skipped because setting up the persistence failed.');
}
}
self::$persistenceWasSetup = true;
}

$this->contentRepositoryId = $contentRepositoryId;

$configurationManager = $this->objectManager->get(ConfigurationManager::class);
$configurationManager = $this->getObject(ConfigurationManager::class);
$registrySettings = $configurationManager->getConfiguration(
ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
'Neos.ContentRepositoryRegistry'
);

$contentRepositoryRegistry = new ContentRepositoryRegistry(
$registrySettings,
$this->objectManager
$this->getObject(ObjectManagerInterface::class)
);

$this->contentRepository = $contentRepositoryRegistry->get($this->contentRepositoryId);
Expand All @@ -57,7 +47,7 @@ private function initCleanContentRepository(ContentRepositoryId $contentReposito
self::$wasContentRepositorySetupCalled = true;
}

$connection = $this->objectManager->get(Connection::class);
$connection = $this->getObject(Connection::class);

// reset events and projections
$eventTableName = sprintf('cr_%s_events', $this->contentRepositoryId->value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Flowpack\NodeTemplates\Tests\Functional\ContentRepositoryTestTrait;
use Flowpack\NodeTemplates\Tests\Functional\FakeNodeTypeManagerTrait;
use Flowpack\NodeTemplates\Tests\Functional\SnapshotTrait;
use Neos\Behat\FlowEntitiesTrait;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode;
Expand Down Expand Up @@ -35,11 +36,12 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\BufferedOutput;

final class StandaloneValidationCommandTest extends TestCase // we don't use Flows functional test case as it would reset the database afterwards
final class StandaloneValidationCommandTest extends TestCase // we don't use Flows functional test case as it would reset the database afterwards (see FlowEntitiesTrait)
{
use SnapshotTrait;
use ContentRepositoryTestTrait;
use FakeNodeTypeManagerTrait;
use FlowEntitiesTrait;

/**
* Matching configuration in Neos.Neos.sites.node-templates-site
Expand Down Expand Up @@ -70,6 +72,7 @@ public function tearDown(): void
private function setupContentRepository(): void
{
$this->initCleanContentRepository(ContentRepositoryId::fromString('node_templates'));
$this->truncateAndSetupFlowEntities();

$this->nodeTypeManager = $this->contentRepository->getNodeTypeManager();
$this->loadFakeNodeTypes();
Expand Down Expand Up @@ -138,4 +141,9 @@ public function itMatchesSnapshot()

$this->assertStringEqualsFileOrCreateSnapshot($this->fixturesDir . '/NodeTemplateValidateOutput.log', $contents);
}

final protected function getObject(string $className): object
{
return $this->objectManager->get($className);
}
}

0 comments on commit 44c0f22

Please sign in to comment.