-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathNodeTouchCommandTest.php
More file actions
116 lines (94 loc) · 3.25 KB
/
NodeTouchCommandTest.php
File metadata and controls
116 lines (94 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
declare(strict_types=1);
namespace PHPCR\Tests\Util\Console\Command;
use PHPCR\NodeType\NodeTypeInterface;
use PHPCR\PathNotFoundException;
use PHPCR\Tests\Stubs\MockNode;
use PHPCR\Util\Console\Command\NodeTouchCommand;
use PHPCR\Util\Console\Helper\PhpcrHelper;
use PHPUnit\Framework\MockObject\MockObject;
/**
* Currently very minimal test for touch command.
*/
class NodeTouchCommandTest extends BaseCommandTest
{
/**
* @var PhpcrHelper&MockObject
*/
public $phpcrHelper;
public function setUp(): void
{
parent::setUp();
$command = new NodeTouchCommand();
$this->addCommand($command);
// Override default concrete instance with mock
$this->phpcrHelper = $this->getMockBuilder(PhpcrHelper::class)
->disableOriginalConstructor()
->getMock();
$this->phpcrHelper
->method('getSession')
->willReturn($this->session);
$this->phpcrHelper
->method('getName')
->willReturn('phpcr');
$this->helperSet->set($this->phpcrHelper);
}
public function testTouch(): void
{
$node = $this->node1;
$child = $this->createMock(MockNode::class);
$this->session->expects($this->exactly(2))
->method('getNode')
->willReturnCallback(function ($path) use ($node) {
switch ($path) {
case '/':
return $node;
case '/cms':
throw new PathNotFoundException();
}
throw new \Exception('Unexpected '.$path);
});
$this->node1->expects($this->once())
->method('addNode')
->with('cms')
->willReturn($child);
$this->session->expects($this->once())
->method('save');
$this->executeCommand('phpcr:node:touch', ['path' => '/cms']);
}
public function testUpdate(): void
{
$nodeType = $this->createMock(NodeTypeInterface::class);
$nodeType->expects($this->once())
->method('getName')
->willReturn('nt:unstructured');
$this->session->expects($this->exactly(1))
->method('getNode')
->with('/cms')
->willReturn($this->node1);
$this->node1->expects($this->once())
->method('getPrimaryNodeType')
->willReturn($nodeType);
$me = $this;
$this->phpcrHelper->expects($this->once())
->method('processNode')
->willReturnCallback(function ($output, $node, $options) use ($me): void {
$me->assertEquals($me->node1, $node);
$me->assertEquals([
'setProp' => ['foo=bar'],
'removeProp' => ['bar'],
'addMixins' => ['foo:bar'],
'removeMixins' => ['bar:foo'],
'dump' => true,
], $options);
});
$this->executeCommand('phpcr:node:touch', [
'path' => '/cms',
'--set-prop' => ['foo=bar'],
'--remove-prop' => ['bar'],
'--add-mixin' => ['foo:bar'],
'--remove-mixin' => ['bar:foo'],
'--dump' => true,
]);
}
}