From 773f5cbff12813fb187f2974d6951ac3a7958a6c Mon Sep 17 00:00:00 2001 From: Bernhard Schmitt Date: Mon, 11 Nov 2024 20:24:05 +0100 Subject: [PATCH] Adjust tests to beta15 --- .../AbstractNodeTemplateTestCase.php | 50 +++++++++++-------- .../Functional/ContentRepositoryTestTrait.php | 4 +- .../StandaloneValidationCommandTest.php | 11 ++-- .../FeedbackCollectionMessagesTrait.php | 3 ++ .../Functional/JsonSerializeNodeTreeTrait.php | 7 +++ Tests/Functional/WithConfigurationTrait.php | 2 +- .../Domain/NodeCreation/PropertyTypeTest.php | 11 +++- .../Domain/NodeCreation/ReferenceTypeTest.php | 5 ++ .../Domain/NodeCreation/TransientNodeTest.php | 12 +++-- 9 files changed, 69 insertions(+), 36 deletions(-) diff --git a/Tests/Functional/AbstractNodeTemplateTestCase.php b/Tests/Functional/AbstractNodeTemplateTestCase.php index 4c8f5c3..0bf613e 100644 --- a/Tests/Functional/AbstractNodeTemplateTestCase.php +++ b/Tests/Functional/AbstractNodeTemplateTestCase.php @@ -18,8 +18,10 @@ use Neos\ContentRepository\Core\Projection\ContentGraph\ContentSubgraphInterface; use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindSubtreeFilter; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\Projection\ContentGraph\Subtree; use Neos\ContentRepository\Core\Projection\ContentGraph\VisibilityConstraints; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\User\UserId; @@ -82,7 +84,7 @@ public function setUp(): void $this->objectManager->setInstance(TemplateConfigurationProcessor::class, $templateFactoryMock); $ref = new \ReflectionClass($this); - $this->fixturesDir = dirname($ref->getFileName()) . '/Snapshots'; + $this->fixturesDir = dirname($ref->getFileName() ?: '') . '/Snapshots'; } public function tearDown(): void @@ -112,8 +114,6 @@ private function setupContentRepository(): void $liveWorkspaceCommand = CreateRootWorkspace::create( $workspaceName = WorkspaceName::fromString('live'), - new WorkspaceTitle('Live'), - new WorkspaceDescription('The live workspace'), ContentStreamId::fromString('cs-identifier') ); @@ -137,19 +137,22 @@ private function setupContentRepository(): void $dimensionSpacePoint = DimensionSpacePoint::fromArray([]) ), $sitesId, - nodeName: NodeName::fromString('test-site') - ); + )->withNodeName(NodeName::fromString('test-site')); $this->contentRepository->handle($siteNodeCommand); $this->subgraph = $this->contentRepository->getContentGraph($workspaceName)->getSubgraph($dimensionSpacePoint, VisibilityConstraints::withoutRestrictions()); - $this->homePageNode = $this->subgraph->findNodeById($testSiteId); + $homePage = $this->subgraph->findNodeById($testSiteId); + assert($homePage instanceof Node); + $this->homePageNode = $homePage; - $this->homePageMainContentCollectionNode = $this->subgraph->findNodeByPath( + $homePageMainCollection = $this->subgraph->findNodeByPath( NodeName::fromString('main'), $testSiteId ); + assert($homePageMainCollection instanceof Node); + $this->homePageMainContentCollectionNode = $homePageMainCollection; // For the case you the Neos Site is expected to return the correct site node you can use: @@ -175,8 +178,8 @@ private function setupContentRepository(): void */ protected function createNodeInto(Node $targetNode, string $nodeTypeName, array $nodeCreationDialogValues): Node { - $targetNodeAddress = NodeAddressFactory::create($this->contentRepository)->createFromNode($targetNode); - $serializedTargetNodeAddress = $targetNodeAddress->serializeForUri(); + $targetNodeAddress = NodeAddress::fromNode($targetNode); + $serializedTargetNodeAddress = $targetNodeAddress->toJson(); $changeCollectionSerialized = [[ 'type' => 'Neos.Neos.Ui:CreateInto', @@ -198,10 +201,12 @@ protected function createNodeInto(Node $targetNode, string $nodeTypeName, array assert($changeCollection instanceof ChangeCollection); $changeCollection->apply(); - return $this->subgraph->findNodeByPath( + $node = $this->subgraph->findNodeByPath( NodeName::fromString('new-node'), $targetNode->aggregateId ); + assert($node instanceof Node); + return $node; } protected function createFakeNode(string $nodeAggregateId): Node @@ -213,11 +218,12 @@ protected function createFakeNode(string $nodeAggregateId): Node NodeTypeName::fromString('unstructured'), $this->homePageNode->originDimensionSpacePoint, $this->homePageNode->aggregateId, - nodeName: NodeName::fromString(uniqid('node-')) - ) + )->withNodeName(NodeName::fromString(uniqid('node-'))) ); - return $this->subgraph->findNodeById($someNodeId); + $node = $this->subgraph->findNodeById($someNodeId); + assert($node instanceof Node); + return $node; } protected function assertLastCreatedTemplateMatchesSnapshot(string $snapShotName): void @@ -225,12 +231,12 @@ protected function assertLastCreatedTemplateMatchesSnapshot(string $snapShotName $lastCreatedTemplate = $this->serializeValuesInArray( $this->lastCreatedRootTemplate->jsonSerialize() ); - $this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.template.json', json_encode($lastCreatedTemplate, JSON_PRETTY_PRINT)); + $this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.template.json', json_encode($lastCreatedTemplate, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)); } protected function assertCaughtExceptionsMatchesSnapshot(string $snapShotName): void { - $this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.messages.json', json_encode($this->getMessagesOfFeedbackCollection(), JSON_PRETTY_PRINT)); + $this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.messages.json', json_encode($this->getMessagesOfFeedbackCollection(), JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)); } protected function assertNoExceptionsWereCaught(): void @@ -240,16 +246,16 @@ protected function assertNoExceptionsWereCaught(): void protected function assertNodeDumpAndTemplateDumpMatchSnapshot(string $snapShotName, Node $node): void { - $serializedNodes = $this->jsonSerializeNodeAndDescendents( - $this->subgraph->findSubtree( - $node->aggregateId, - FindSubtreeFilter::create( - nodeTypes: 'Neos.Neos:Node' - ) + $subtree = $this->subgraph->findSubtree( + $node->aggregateId, + FindSubtreeFilter::create( + nodeTypes: 'Neos.Neos:Node' ) ); + assert($subtree instanceof Subtree); + $serializedNodes = $this->jsonSerializeNodeAndDescendents($subtree); unset($serializedNodes['nodeTypeName']); - $this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.nodes.json', json_encode($serializedNodes, JSON_PRETTY_PRINT)); + $this->assertJsonStringEqualsJsonFileOrCreateSnapshot($this->fixturesDir . '/' . $snapShotName . '.nodes.json', json_encode($serializedNodes, JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR)); $dumpedYamlTemplate = $this->nodeTemplateDumper->createNodeTemplateYamlDumpFromSubtree($node, $this->contentRepository); diff --git a/Tests/Functional/ContentRepositoryTestTrait.php b/Tests/Functional/ContentRepositoryTestTrait.php index 4e42564..ae760f3 100644 --- a/Tests/Functional/ContentRepositoryTestTrait.php +++ b/Tests/Functional/ContentRepositoryTestTrait.php @@ -6,6 +6,7 @@ use Neos\ContentRepository\Core\ContentRepository; use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; +use Neos\ContentRepositoryRegistry\SubgraphCachingInMemory\SubgraphCachePool; use Neos\Flow\Configuration\ConfigurationManager; use Neos\Flow\ObjectManagement\ObjectManagerInterface; @@ -37,7 +38,8 @@ private function initCleanContentRepository(ContentRepositoryId $contentReposito $contentRepositoryRegistry = new ContentRepositoryRegistry( $registrySettings, - $this->getObject(ObjectManagerInterface::class) + $this->getObject(ObjectManagerInterface::class), + new SubgraphCachePool(), ); $this->contentRepository = $contentRepositoryRegistry->get($this->contentRepositoryId); diff --git a/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php b/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php index ae66abb..8eb1f0d 100644 --- a/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php +++ b/Tests/Functional/Features/StandaloneValidationCommand/StandaloneValidationCommandTest.php @@ -21,9 +21,7 @@ use Neos\ContentRepository\Core\SharedModel\Node\NodeName; use Neos\ContentRepository\Core\SharedModel\User\UserId; use Neos\ContentRepository\Core\SharedModel\Workspace\ContentStreamId; -use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceDescription; use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; -use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceTitle; use Neos\ContentRepository\TestSuite\Behavior\Features\Bootstrap\Helpers\FakeUserIdProvider; use Neos\Flow\Cli\Exception\StopCommandException; use Neos\Flow\Cli\Response; @@ -61,7 +59,7 @@ public function setUp(): void $this->setupContentRepository(); $ref = new \ReflectionClass($this); - $this->fixturesDir = dirname($ref->getFileName()) . '/Snapshots'; + $this->fixturesDir = dirname($ref->getFileName() ?: '') . '/Snapshots'; } public function tearDown(): void @@ -90,8 +88,6 @@ private function setupContentRepository(): void $liveWorkspaceCommand = CreateRootWorkspace::create( $workspaceName = WorkspaceName::fromString('live'), - new WorkspaceTitle('Live'), - new WorkspaceDescription('The live workspace'), ContentStreamId::fromString('cs-identifier') ); @@ -115,14 +111,13 @@ private function setupContentRepository(): void DimensionSpacePoint::fromArray([]) ), $sitesId, - nodeName: NodeName::fromString(self::TEST_SITE_NAME) - ); + )->withNodeName(NodeName::fromString(self::TEST_SITE_NAME)); $this->contentRepository->handle($siteNodeCommand); } /** @test */ - public function itMatchesSnapshot() + public function itMatchesSnapshot(): void { $commandController = $this->getObject(NodeTemplateCommandController::class); diff --git a/Tests/Functional/FeedbackCollectionMessagesTrait.php b/Tests/Functional/FeedbackCollectionMessagesTrait.php index bf56190..d3ea32d 100644 --- a/Tests/Functional/FeedbackCollectionMessagesTrait.php +++ b/Tests/Functional/FeedbackCollectionMessagesTrait.php @@ -18,6 +18,9 @@ trait FeedbackCollectionMessagesTrait */ abstract protected function getObject(string $className): object; + /** + * @return array + */ private function getMessagesOfFeedbackCollection(): array { /** @var FeedbackInterface[] $allFeedbacks */ diff --git a/Tests/Functional/JsonSerializeNodeTreeTrait.php b/Tests/Functional/JsonSerializeNodeTreeTrait.php index 161a675..41acdf0 100644 --- a/Tests/Functional/JsonSerializeNodeTreeTrait.php +++ b/Tests/Functional/JsonSerializeNodeTreeTrait.php @@ -13,6 +13,9 @@ trait JsonSerializeNodeTreeTrait { private readonly ContentRepository $contentRepository; + /** + * @return array + */ private function jsonSerializeNodeAndDescendents(Subtree $subtree): array { $node = $subtree->node; @@ -48,6 +51,10 @@ private function jsonSerializeNodeAndDescendents(Subtree $subtree): array ]); } + /** + * @param array $array + * @return array + */ private function serializeValuesInArray(array $array): array { foreach ($array as $key => $value) { diff --git a/Tests/Functional/WithConfigurationTrait.php b/Tests/Functional/WithConfigurationTrait.php index 7469708..a962c94 100644 --- a/Tests/Functional/WithConfigurationTrait.php +++ b/Tests/Functional/WithConfigurationTrait.php @@ -13,7 +13,7 @@ trait WithConfigurationTrait * WARNING: If you activate Singletons during this transaction they will later still have a reference to the mocked object manger, so you might need to call * {@see ObjectManagerInterface::forgetInstance()}. An alternative would be also to hack the protected $this->settings of the manager. * - * @param array $additionalSettings settings that are merged onto the the current testing configuration + * @param array $additionalSettings settings that are merged onto the the current testing configuration * @param callable $fn test code that is executed in the modified context */ private function withMockedConfigurationSettings(array $additionalSettings, callable $fn): void diff --git a/Tests/Unit/Domain/NodeCreation/PropertyTypeTest.php b/Tests/Unit/Domain/NodeCreation/PropertyTypeTest.php index 8f8ff03..23f934e 100644 --- a/Tests/Unit/Domain/NodeCreation/PropertyTypeTest.php +++ b/Tests/Unit/Domain/NodeCreation/PropertyTypeTest.php @@ -36,6 +36,9 @@ class PropertyTypeTest extends TestCase { /** * @dataProvider declarationAndValueProvider + * @param array $declarationsByType, + * @param array $validValues, + * @param array $invalidValues, */ public function testIsMatchedBy(array $declarationsByType, array $validValues, array $invalidValues): void { @@ -64,6 +67,9 @@ public function testIsMatchedBy(array $declarationsByType, array $validValues, a } } + /** + * @return array> + */ public function declarationAndValueProvider(): array { $bool = true; @@ -148,7 +154,7 @@ public function declarationAndValueProvider(): array /** * @dataProvider declarationTypeProvider - * @param array $declaredTypes + * @param array $declaredTypes * @param string $expectedSerializationType */ public function testGetValue(array $declaredTypes, string $expectedSerializationType): void @@ -178,6 +184,9 @@ public function testGetValue(array $declaredTypes, string $expectedSerialization } } + /** + * @return array> + */ public function declarationTypeProvider(): array { return [ diff --git a/Tests/Unit/Domain/NodeCreation/ReferenceTypeTest.php b/Tests/Unit/Domain/NodeCreation/ReferenceTypeTest.php index 8779449..6505866 100644 --- a/Tests/Unit/Domain/NodeCreation/ReferenceTypeTest.php +++ b/Tests/Unit/Domain/NodeCreation/ReferenceTypeTest.php @@ -25,6 +25,8 @@ class ReferenceTypeTest extends TestCase /** * @dataProvider declarationAndValueProvider + * @param array $validValues, + * @param array $invalidValues */ public function testIsMatchedBy(string $declarationType, array $validValues, array $invalidValues): void { @@ -57,6 +59,9 @@ public function testIsMatchedBy(string $declarationType, array $validValues, arr } } + /** + * @return array> + */ public function declarationAndValueProvider(): array { $int = 13; diff --git a/Tests/Unit/Domain/NodeCreation/TransientNodeTest.php b/Tests/Unit/Domain/NodeCreation/TransientNodeTest.php index a2ab176..a0fb18c 100644 --- a/Tests/Unit/Domain/NodeCreation/TransientNodeTest.php +++ b/Tests/Unit/Domain/NodeCreation/TransientNodeTest.php @@ -159,11 +159,12 @@ public function forRegularChildNodeDisallowedChildNode(): void /** @test */ public function splitPropertiesAndReferencesByTypeDeclaration(): void { + $nodeType = $this->getNodeType('A:ContentWithProperties'); $node = TransientNode::forRegular( NodeAggregateId::fromString('na'), WorkspaceName::fromString('ws'), OriginDimensionSpacePoint::fromArray([]), - $this->getNodeType('A:ContentWithProperties'), + $nodeType, NodeAggregateIdsByNodePaths::createEmpty(), new NodeTypeManager(fn () => []), $this->getMockBuilder(ContentSubgraphInterface::class)->disableOriginalConstructor()->getMock(), @@ -213,8 +214,13 @@ private function createFakeRegularTransientNode(string $nodeTypeName): Transient /** * Return a nodetype built from the nodeTypesFixture */ - private function getNodeType(string $nodeTypeName): ?NodeType + private function getNodeType(string $nodeTypeName): NodeType { - return $this->nodeTypeManager->getNodeType($nodeTypeName); + $nodeType = $this->nodeTypeManager->getNodeType($nodeTypeName); + if (!$nodeType) { + throw new \Exception('Unknown node type ' . $nodeTypeName); + } + + return $nodeType; } }