Skip to content

Commit

Permalink
Merge pull request #2660 from daniellienert/task/further-cleanip-tests
Browse files Browse the repository at this point in the history
TASK: Further cleanup tests
  • Loading branch information
daniellienert committed Sep 2, 2019
2 parents 1d19a6e + c79583b commit 097df96
Show file tree
Hide file tree
Showing 67 changed files with 680 additions and 673 deletions.
Expand Up @@ -108,7 +108,7 @@ public function createContextMatchingNodeDataCreatesMatchingContext()
$this->inject($this->nodeFactory, 'contextFactory', $mockContextFactory);

$mockNodeData = $this->getMockBuilder(NodeData::class)->disableOriginalConstructor()->getMock();
$mockNodeData->expects(self::any())->method('getWorkspace')->will($this->returnValue($mockWorkspace));
$mockNodeData->expects(self::any())->method('getWorkspace')->will(self::returnValue($mockWorkspace));
$mockNodeData->expects(self::any())->method('getDimensionValues')->willReturn($dimensionValues);

$context = $this->nodeFactory->createContextMatchingNodeData($mockNodeData);
Expand Down

Large diffs are not rendered by default.

104 changes: 52 additions & 52 deletions Neos.ContentRepository/Tests/Unit/Domain/Model/NodeDataTest.php

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions Neos.ContentRepository/Tests/Unit/Domain/Model/NodeTest.php
Expand Up @@ -39,19 +39,19 @@ public function createNodeFromTemplateUsesWorkspaceFromContextForNodeData()
$mockFirstLevelNodeCache = $this->createMock(FirstLevelNodeCache::class);
$newNode = $this->getMockBuilder(Node::class)->disableOriginalConstructor()->getMock();
$context = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
$context->expects($this->any())->method('getFirstLevelNodeCache')->will($this->returnValue($mockFirstLevelNodeCache));
$context->expects(self::any())->method('getFirstLevelNodeCache')->will(self::returnValue($mockFirstLevelNodeCache));
$nodeTemplate = new NodeTemplate();

$context->expects($this->any())->method('getWorkspace')->will($this->returnValue($workspace));
$context->expects(self::any())->method('getWorkspace')->will(self::returnValue($workspace));

$nodeFactory = $this->createMock(NodeFactory::class);

$parentNode = new Node($parentNodeData, $context);

$this->inject($parentNode, 'nodeFactory', $nodeFactory);

$parentNodeData->expects($this->atLeastOnce())->method('createNodeDataFromTemplate')->with($nodeTemplate, 'bar', $workspace)->will($this->returnValue($newNodeData));
$nodeFactory->expects($this->atLeastOnce())->method('createFromNodeData')->with($newNodeData, $context)->will($this->returnValue($newNode));
$parentNodeData->expects(self::atLeastOnce())->method('createNodeDataFromTemplate')->with($nodeTemplate, 'bar', $workspace)->will(self::returnValue($newNodeData));
$nodeFactory->expects(self::atLeastOnce())->method('createFromNodeData')->with($newNodeData, $context)->will(self::returnValue($newNode));

$parentNode->createNodeFromTemplate($nodeTemplate, 'bar');
}
Expand All @@ -63,7 +63,7 @@ public function createNodeFromTemplateUsesWorkspaceFromContextForNodeData()
public function getPrimaryChildNodeReturnsTheFirstChildNode()
{
$mockNodeData = $this->getMockBuilder(NodeData::class)->disableOriginalConstructor()->getMock();
$mockNodeData->expects($this->any())->method('getPath')->will($this->returnValue('/foo/bar'));
$mockNodeData->expects(self::any())->method('getPath')->will(self::returnValue('/foo/bar'));
$mockContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();


Expand All @@ -73,7 +73,7 @@ public function getPrimaryChildNodeReturnsTheFirstChildNode()
$this->inject($node, 'nodeDataRepository', $mockNodeDataRepository);

$expectedNode = $this->createMock(NodeInterface::class);
$mockNodeDataRepository->expects($this->once())->method('findFirstByParentAndNodeTypeInContext')->with('/foo/bar', null, $mockContext)->will($this->returnValue($expectedNode));
$mockNodeDataRepository->expects(self::once())->method('findFirstByParentAndNodeTypeInContext')->with('/foo/bar', null, $mockContext)->will(self::returnValue($expectedNode));

$primaryChildNode = $node->getPrimaryChildNode();

Expand Down Expand Up @@ -189,27 +189,27 @@ public function contextPathPatternShouldNotMatchOnInvalidPaths($path)
public function createNodeWithAutoCreatedChildNodesAndNoIdentifierUsesGeneratedIdentifierOfNodeForChildNodes()
{
$mockContext = $this->getMockBuilder(Context::class)->disableOriginalConstructor()->getMock();
$mockContext->expects($this->any())->method('getTargetDimensions')->will($this->returnValue(['language' => 'mul_ZZ']));
$mockContext->expects(self::any())->method('getTargetDimensions')->will(self::returnValue(['language' => 'mul_ZZ']));
$mockFirstLevelNodeCache = $this->createMock(FirstLevelNodeCache::class);
$mockContext->expects($this->any())->method('getFirstLevelNodeCache')->will($this->returnValue($mockFirstLevelNodeCache));
$mockContext->expects(self::any())->method('getFirstLevelNodeCache')->will(self::returnValue($mockFirstLevelNodeCache));

$mockNodeData = $this->getMockBuilder(NodeData::class)->disableOriginalConstructor()->getMock();
$mockNodeType = $this->getMockBuilder(NodeType::class)->disableOriginalConstructor()->getMock();
$mockSubNodeType = $this->getMockBuilder(NodeType::class)->disableOriginalConstructor()->getMock();

$mockNodeType->expects($this->any())->method('getDefaultValuesForProperties')->will($this->returnValue([]));
$mockNodeType->expects($this->any())->method('getAutoCreatedChildNodes')->will($this->returnValue([
$mockNodeType->expects(self::any())->method('getDefaultValuesForProperties')->will(self::returnValue([]));
$mockNodeType->expects(self::any())->method('getAutoCreatedChildNodes')->will(self::returnValue([
'subnode1' => $mockSubNodeType
]));

$i = 0;
$generatedIdentifiers = [];
$node = $this->getMockBuilder(Node::class)->setMethods(['createSingleNode'])->setConstructorArgs([$mockNodeData, $mockContext])->getMock();
$node->expects($this->any())->method('createSingleNode')->will($this->returnCallback(function () use (&$i, &$generatedIdentifiers, $mockSubNodeType) {
$node->expects(self::any())->method('createSingleNode')->will(self::returnCallback(function () use (&$i, &$generatedIdentifiers, $mockSubNodeType) {
$newNode = $this->createMock(NodeInterface::class);
$newNode->expects($this->any())->method('getIdentifier')->will($this->returnValue('node-' . $i++));
$newNode->expects(self::any())->method('getIdentifier')->will(self::returnValue('node-' . $i++));

$newNode->expects($this->once())->method('createNode')->with('subnode1', $mockSubNodeType, $this->callback(function ($identifier) use (&$generatedIdentifiers, $i) {
$newNode->expects(self::once())->method('createNode')->with('subnode1', $mockSubNodeType, $this->callback(function ($identifier) use (&$generatedIdentifiers, $i) {
$generatedIdentifiers[$i] = $identifier;
return true;
}));
Expand Down
Expand Up @@ -219,7 +219,7 @@ public function propertiesAreEmptyArrayByDefault()
public function hasConfigurationInitializesTheNodeType()
{
$nodeType = $this->getMockBuilder(NodeType::class)->disableOriginalConstructor()->setMethods(['initialize'])->getMock();
$nodeType->expects($this->once())->method('initialize');
$nodeType->expects(self::once())->method('initialize');
$nodeType->hasConfiguration('foo');
}

Expand Down Expand Up @@ -251,7 +251,7 @@ public function hasConfigurationReturnsFalseIfSpecifiedConfigurationPathDoesNotE
public function getConfigurationInitializesTheNodeType()
{
$nodeType = $this->getMockBuilder(NodeType::class)->disableOriginalConstructor()->setMethods(['initialize'])->getMock();
$nodeType->expects($this->once())->method('initialize');
$nodeType->expects(self::once())->method('initialize');
$nodeType->getConfiguration('foo');
}

Expand Down Expand Up @@ -302,7 +302,7 @@ public function accessingConfigurationOptionsInitializesTheNodeType($getter)
$mockObjectManager = $this->createMock(ObjectManagerInterface::class);
$nodeType = $this->getAccessibleMock(NodeType::class, ['initialize'], [], '', false);
$nodeType->_set('objectManager', $mockObjectManager);
$nodeType->expects($this->atLeastOnce())->method('initialize');
$nodeType->expects(self::atLeastOnce())->method('initialize');
$nodeType->$getter();
}

Expand Down Expand Up @@ -456,7 +456,7 @@ public function getAutoCreatedChildNodesReturnsLowercasePaths()
'childNodes' => ['nodeName' => $childNodeConfiguration]
]);
$mockNodeTypeManager = $this->getMockBuilder(NodeTypeManager::class)->disableOriginalConstructor()->getMock();
$mockNodeTypeManager->expects($this->any())->method('getNodeType')->will($this->returnValue($baseType));
$mockNodeTypeManager->expects(self::any())->method('getNodeType')->will(self::returnValue($baseType));
$this->inject($baseType, 'nodeTypeManager', $mockNodeTypeManager);

$autoCreatedChildNodes = $mockNodeTypeManager->getNodeType('Neos.ContentRepository:Base')->getAutoCreatedChildNodes();
Expand Down
14 changes: 7 additions & 7 deletions Neos.ContentRepository/Tests/Unit/Domain/Model/WorkspaceTest.php
Expand Up @@ -45,7 +45,7 @@ public function onInitializationANewlyCreatedWorkspaceCreatesItsOwnRootNode()
$workspace = $this->getAccessibleMock(Workspace::class, ['dummy'], [], '', false);

$mockNodeDataRepository = $this->getMockBuilder(NodeDataRepository::class)->disableOriginalConstructor()->setMethods(['add'])->getMock();
$mockNodeDataRepository->expects($this->once())->method('add');
$mockNodeDataRepository->expects(self::once())->method('add');

$workspace->_set('nodeDataRepository', $mockNodeDataRepository);

Expand All @@ -64,7 +64,7 @@ public function getNodeCountCallsRepositoryFunction()
$workspace = $this->getAccessibleMock(Workspace::class, ['dummy'], [], '', false);
$workspace->_set('nodeDataRepository', $mockNodeDataRepository);

$mockNodeDataRepository->expects($this->once())->method('countByWorkspace')->with($workspace)->will($this->returnValue(42));
$mockNodeDataRepository->expects(self::once())->method('countByWorkspace')->with($workspace)->will(self::returnValue(42));

self::assertSame(42, $workspace->getNodeCount());
}
Expand All @@ -77,7 +77,7 @@ public function publishNodeReturnsIfTheCurrentWorkspaceHasNoBaseWorkspace()
$targetWorkspace = new Workspace('live');

$currentWorkspace = $this->getAccessibleMock(Workspace::class, ['verifyPublishingTargetWorkspace'], ['live']);
$currentWorkspace->expects($this->never())->method('verifyPublishingTargetWorkspace');
$currentWorkspace->expects(self::never())->method('verifyPublishingTargetWorkspace');

$mockNode = $this->getMockBuilder(NodeInterface::class)->disableOriginalConstructor()->getMock();

Expand All @@ -98,9 +98,9 @@ public function publishNodeReturnsIfTheTargetWorkspaceIsTheSameAsTheSourceWorksp
$workspace->setBaseWorkspace($liveWorkspace);

$mockNode = $this->getMockBuilder(NodeInterface::class)->disableOriginalConstructor()->getMock();
$mockNode->expects($this->any())->method('getWorkspace')->will($this->returnValue($workspace));
$mockNode->expects(self::any())->method('getWorkspace')->will(self::returnValue($workspace));

$workspace->expects($this->never())->method('emitBeforeNodePublishing');
$workspace->expects(self::never())->method('emitBeforeNodePublishing');

$workspace->publishNode($mockNode, $workspace);
}
Expand Down Expand Up @@ -188,9 +188,9 @@ public function publishNodeWithANodeInTheTargetWorkspaceShouldDoNothing()
$this->inject($liveWorkspace, 'nodeDataRepository', $nodeDataRepository);

$node = $this->createMock(NodeInterface::class);
$node->expects($this->any())->method('getWorkspace')->will($this->returnValue($liveWorkspace));
$node->expects(self::any())->method('getWorkspace')->will(self::returnValue($liveWorkspace));

$nodeDataRepository->expects($this->never())->method('findOneByIdentifier');
$nodeDataRepository->expects(self::never())->method('findOneByIdentifier');

$personalWorkspace->publishNode($node, $liveWorkspace);
}
Expand Down

0 comments on commit 097df96

Please sign in to comment.