diff --git a/Tests/Functional/AbstractNodeTemplateTestCase.php b/Tests/Functional/AbstractNodeTemplateTestCase.php index dfdf1f2..d78ab3a 100644 --- a/Tests/Functional/AbstractNodeTemplateTestCase.php +++ b/Tests/Functional/AbstractNodeTemplateTestCase.php @@ -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; @@ -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; @@ -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(); @@ -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); + } } diff --git a/Tests/Functional/ContentRepositoryTestTrait.php b/Tests/Functional/ContentRepositoryTestTrait.php index 386f90b..4e42564 100644 --- a/Tests/Functional/ContentRepositoryTestTrait.php +++ b/Tests/Functional/ContentRepositoryTestTrait.php @@ -7,39 +7,29 @@ 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 $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' @@ -47,7 +37,7 @@ private function initCleanContentRepository(ContentRepositoryId $contentReposito $contentRepositoryRegistry = new ContentRepositoryRegistry( $registrySettings, - $this->objectManager + $this->getObject(ObjectManagerInterface::class) ); $this->contentRepository = $contentRepositoryRegistry->get($this->contentRepositoryId); @@ -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); diff --git a/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php b/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php index 6b45d97..5d10b3a 100644 --- a/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php +++ b/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php @@ -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; @@ -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 @@ -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(); @@ -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); + } }