Skip to content

Commit 44c0f22

Browse files
committed
TASK: Use FlowEntitiesTrait::truncateAndSetupFlowEntities to reset persistence
Previously the doctrine entities would still exist of the previous test.
1 parent 96bd529 commit 44c0f22

3 files changed

Lines changed: 30 additions & 24 deletions

File tree

Tests/Functional/AbstractNodeTemplateTestCase.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Flowpack\NodeTemplates\Domain\NodeTemplateDumper\NodeTemplateDumper;
88
use Flowpack\NodeTemplates\Domain\Template\RootTemplate;
99
use Flowpack\NodeTemplates\Domain\TemplateConfiguration\TemplateConfigurationProcessor;
10+
use Neos\Behat\FlowEntitiesTrait;
1011
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
1112
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
1213
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode;
@@ -35,13 +36,14 @@
3536
use Neos\Neos\Ui\TypeConverter\ChangeCollectionConverter;
3637
use PHPUnit\Framework\TestCase;
3738

38-
abstract class AbstractNodeTemplateTestCase extends TestCase // we don't use Flows functional test case as it would reset the database afterwards
39+
abstract class AbstractNodeTemplateTestCase extends TestCase // we don't use Flows functional test case as it would reset the database afterwards (see FlowEntitiesTrait)
3940
{
4041
use SnapshotTrait;
4142
use FeedbackCollectionMessagesTrait;
4243
use JsonSerializeNodeTreeTrait;
4344
use WithConfigurationTrait;
4445
use FakeNodeTypeManagerTrait;
46+
use FlowEntitiesTrait;
4547

4648
use ContentRepositoryTestTrait;
4749

@@ -91,6 +93,7 @@ public function tearDown(): void
9193
private function setupContentRepository(): void
9294
{
9395
$this->initCleanContentRepository(ContentRepositoryId::fromString('node_templates'));
96+
$this->truncateAndSetupFlowEntities();
9497

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

243246
$this->assertStringEqualsFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.yaml', $yamlTemplateWithoutOriginNodeTypeName);
244247
}
248+
249+
final protected function getObject(string $className): object
250+
{
251+
return $this->objectManager->get($className);
252+
}
245253
}

Tests/Functional/ContentRepositoryTestTrait.php

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,37 @@
77
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
88
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
99
use Neos\Flow\Configuration\ConfigurationManager;
10-
use Neos\Flow\ObjectManagement\ObjectManager;
11-
use Neos\Flow\Persistence\Doctrine\PersistenceManager;
10+
use Neos\Flow\ObjectManagement\ObjectManagerInterface;
1211

13-
/**
14-
* @property ObjectManager $objectManager
15-
*/
1612
trait ContentRepositoryTestTrait
1713
{
1814
private readonly ContentRepository $contentRepository;
1915

2016
private readonly ContentRepositoryId $contentRepositoryId;
2117

22-
private static bool $persistenceWasSetup = false;
23-
2418
private static bool $wasContentRepositorySetupCalled = false;
2519

20+
/**
21+
* @template T of object
22+
* @param class-string<T> $className
23+
*
24+
* @return T
25+
*/
26+
abstract protected function getObject(string $className): object;
27+
2628
private function initCleanContentRepository(ContentRepositoryId $contentRepositoryId): void
2729
{
28-
if (!self::$persistenceWasSetup) {
29-
// TODO super hacky and as we never clean up !!!
30-
$persistenceManager = $this->objectManager->get(PersistenceManager::class);
31-
if (is_callable([$persistenceManager, 'compile'])) {
32-
$result = $persistenceManager->compile();
33-
if ($result === false) {
34-
self::markTestSkipped('Test skipped because setting up the persistence failed.');
35-
}
36-
}
37-
self::$persistenceWasSetup = true;
38-
}
39-
4030
$this->contentRepositoryId = $contentRepositoryId;
4131

42-
$configurationManager = $this->objectManager->get(ConfigurationManager::class);
32+
$configurationManager = $this->getObject(ConfigurationManager::class);
4333
$registrySettings = $configurationManager->getConfiguration(
4434
ConfigurationManager::CONFIGURATION_TYPE_SETTINGS,
4535
'Neos.ContentRepositoryRegistry'
4636
);
4737

4838
$contentRepositoryRegistry = new ContentRepositoryRegistry(
4939
$registrySettings,
50-
$this->objectManager
40+
$this->getObject(ObjectManagerInterface::class)
5141
);
5242

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

60-
$connection = $this->objectManager->get(Connection::class);
50+
$connection = $this->getObject(Connection::class);
6151

6252
// reset events and projections
6353
$eventTableName = sprintf('cr_%s_events', $this->contentRepositoryId->value);

Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Flowpack\NodeTemplates\Tests\Functional\ContentRepositoryTestTrait;
99
use Flowpack\NodeTemplates\Tests\Functional\FakeNodeTypeManagerTrait;
1010
use Flowpack\NodeTemplates\Tests\Functional\SnapshotTrait;
11+
use Neos\Behat\FlowEntitiesTrait;
1112
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
1213
use Neos\ContentRepository\Core\DimensionSpace\OriginDimensionSpacePoint;
1314
use Neos\ContentRepository\Core\Feature\NodeCreation\Command\CreateNodeAggregateWithNode;
@@ -35,11 +36,12 @@
3536
use PHPUnit\Framework\TestCase;
3637
use Symfony\Component\Console\Output\BufferedOutput;
3738

38-
final class StandaloneValidationCommandTest extends TestCase // we don't use Flows functional test case as it would reset the database afterwards
39+
final class StandaloneValidationCommandTest extends TestCase // we don't use Flows functional test case as it would reset the database afterwards (see FlowEntitiesTrait)
3940
{
4041
use SnapshotTrait;
4142
use ContentRepositoryTestTrait;
4243
use FakeNodeTypeManagerTrait;
44+
use FlowEntitiesTrait;
4345

4446
/**
4547
* Matching configuration in Neos.Neos.sites.node-templates-site
@@ -70,6 +72,7 @@ public function tearDown(): void
7072
private function setupContentRepository(): void
7173
{
7274
$this->initCleanContentRepository(ContentRepositoryId::fromString('node_templates'));
75+
$this->truncateAndSetupFlowEntities();
7376

7477
$this->nodeTypeManager = $this->contentRepository->getNodeTypeManager();
7578
$this->loadFakeNodeTypes();
@@ -138,4 +141,9 @@ public function itMatchesSnapshot()
138141

139142
$this->assertStringEqualsFileOrCreateSnapshot($this->fixturesDir . '/NodeTemplateValidateOutput.log', $contents);
140143
}
144+
145+
final protected function getObject(string $className): object
146+
{
147+
return $this->objectManager->get($className);
148+
}
141149
}

0 commit comments

Comments
 (0)