Skip to content

Commit 304c632

Browse files
committed
Everything unit test except the child nodes works
1 parent ea1318e commit 304c632

File tree

8 files changed

+220
-266
lines changed

8 files changed

+220
-266
lines changed

src/PE/Enums/ActionVariable.php

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/PE/Variables/Types/NodeAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function _gatherAccessorParameters($options, $parameters) {
8585
$actionVariables = array();
8686
foreach ($parameters as $parameter) {
8787
if (!array_key_exists($parameter, $options)) {
88-
throw new VariableTypeException(sprintf('Action variable id "%s" is not known', $parameter));
88+
throw new VariableTypeException(sprintf('Parameter with id "%s" is not known', $parameter));
8989
}
9090
array_push($actionVariables, $options[$parameter]);
9191
}

tests/PE/Nodes/Specials/EncoderNodeVariableApplyToSetterNode.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function __construct() {
1717
parent::__construct('encoder-node-variable-apply-to-setters-node', 'encoder-node-variable-apply-to-setters-node', '\\PE\\Samples\\Specials');
1818

1919
$nodeSimple = $this->addVariable(new EncoderNodeVariable('node-simple'));
20-
$nodeSimple->postNodeSetter(new PostNodeSetter('nodeSimple', NodeAccessor::VARIABLE_NAME));
20+
$nodeSimple->postNodeSetter(new PostNodeSetter('nodeSimple', array(NodeAccessor::VARIABLE_NAME)));
2121

2222
$nodeFull = $this->addVariable(new EncoderNodeVariable('node-full'));
2323
$nodeFull->postNodeSetter(new PostNodeSetter('nodeFull', array(
@@ -40,12 +40,6 @@ function __construct() {
4040
$nodeUnknownVariable->postNodeSetter(new PostNodeSetter('nodeSimple', array('unknown_variable')));
4141

4242
$this->addVariable(new EncoderNodeVariable('var'));
43-
44-
$objectUsingSetterMethod = $this->addVariable(new EncoderNodeVariable('object-using-setter-method'));
45-
$objectUsingSetterMethod->objectSetter(new ObjectSetter('setVar'));
46-
47-
$objectUsingUnknownSetterMethod = $this->addVariable(new EncoderNodeVariable('object-using-unknown-setter-method'));
48-
$objectUsingUnknownSetterMethod->objectSetter(new ObjectSetter('unknownMethod'));
4943
}
5044

5145
public function nodeSimple($nodeData, $setterName) {

tests/PE/Tests/Nodes/EncoderNodeVariableTest.php

Lines changed: 2 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
use PE\Enums\ActionVariable;
66
use PE\Nodes\EncoderNodeVariable;
77
use PE\Tests\Samples;
8+
use PE\Variables\Types\NodeAccessor;
89
use PE\Variables\Types\ObjectGetter;
910
use PE\Variables\Types\ObjectSetter;
11+
use PE\Variables\Types\PostNodeSetter;
1012

1113
class EncoderNodeVariableTest extends Samples {
1214

@@ -113,203 +115,4 @@ public function testProcessValueUnknownTypeException() {
113115
$variable->setType('unknown');
114116
$variable->getObjectSetter()->processValue('string');
115117
}
116-
117-
public function testCallNodeSetterAction() {
118-
$node = $this->getAccessorMethodActionTypeNodeNode();
119-
$variable = $node->getVariable('node');
120-
121-
$this->assertEquals(array(
122-
'node' => 'hello world',
123-
'special' => 'hello world',
124-
), $variable->callNodeSetterAction($node, array(
125-
ActionVariable::GETTER_NODE_DATA => array(
126-
'node' => 'hello world',
127-
),
128-
ActionVariable::GETTER_NAME => 'node'
129-
)));
130-
}
131-
132-
public function testCallNodeSetterActionWithActionTypeNotNode() {
133-
$node = $this->getAccessorMethodActionTypeNodeNode();
134-
$variable = $node->getVariable('node');
135-
$setterAction = $variable->getSetterAction();
136-
$setterAction['type'] = 'not-node';
137-
$variable->setSetterAction($setterAction);
138-
139-
$this->assertNull($variable->callNodeSetterAction($node, array(
140-
ActionVariable::GETTER_NODE_DATA => array(
141-
'node' => 'hello world',
142-
),
143-
ActionVariable::GETTER_NAME => 'node'
144-
)));
145-
}
146-
147-
public function testCallNodeSetterActionWithMissingVariable() {
148-
$this->setExpectedException('\\PE\\Exceptions\\EncoderNodeVariableException', 'Action variable "node_data" is not known');
149-
$node = $this->getAccessorMethodActionTypeNodeNode();
150-
$this->getAccessorMethodActionTypeNodeNode()->getVariable('node')->callNodeSetterAction($node, array());
151-
}
152-
153-
public function testCallNodeSetterActionWithoutMethod() {
154-
$this->setExpectedException('\\PE\\Exceptions\\EncoderNodeVariableException', 'Either method must be a string or an array with a "method" key being a string');
155-
$node = $this->getAccessorMethodActionTypeNodeNode();
156-
$variable = $node->getVariable('node');
157-
$setterAction = $variable->getSetterAction();
158-
unset($setterAction['method']);
159-
$variable->setSetterAction($setterAction);
160-
161-
$variable->callNodeSetterAction($node, array(
162-
ActionVariable::GETTER_NODE_DATA => array(
163-
'node' => 'hello world',
164-
),
165-
ActionVariable::GETTER_NAME => 'node'
166-
));
167-
}
168-
169-
public function testCallNodeGetterAction() {
170-
$node = $this->getAccessorMethodActionTypeNodeNode();
171-
$variable = $node->getVariable('node');
172-
173-
$this->assertEquals(array(
174-
'node' => 'hello world',
175-
'special' => 'hello world getter',
176-
), $variable->callNodeGetterAction($node, array(
177-
ActionVariable::GETTER_NODE_DATA => array(
178-
'node' => 'hello world',
179-
),
180-
ActionVariable::GETTER_NAME => 'node'
181-
)));
182-
}
183-
184-
public function testCallNodeGetterActionWithActionTypeNotNode() {
185-
$node = $this->getAccessorMethodActionTypeNodeNode();
186-
$variable = $node->getVariable('node');
187-
$setterAction = $variable->getGetterAction();
188-
$setterAction['type'] = 'not-node';
189-
$variable->setGetterAction($setterAction);
190-
191-
$this->assertNull($variable->callNodeGetterAction($node, array(
192-
ActionVariable::GETTER_NODE_DATA => array(
193-
'node' => 'hello world',
194-
),
195-
ActionVariable::GETTER_NAME => 'node'
196-
)));
197-
}
198-
199-
200-
public function testApplyToSetterNodeSimple() {
201-
$node = $this->getEncoderNodeVariableApplyToSetterNode();
202-
203-
$object = $this->getEncoderNodeVariableApplyToSetter();
204-
$var = $node->getVariableById('node-simple');
205-
206-
$this->assertEquals(array(
207-
'node' => 'test',
208-
'copied' => 'test',
209-
), $var->applyToSetter(array(
210-
ActionVariable::SETTER_OBJECT => $object,
211-
ActionVariable::SETTER_NODE_DATA => array(
212-
'node' => 'test'
213-
),
214-
ActionVariable::SETTER_NODE => $node,
215-
ActionVariable::SETTER_NAME => 'node',
216-
ActionVariable::SETTER_VALUE => 'test'
217-
)));
218-
219-
$this->assertNull($object->getVar());
220-
}
221-
222-
public function testApplyToSetterNodeFull() {
223-
$node = $this->getEncoderNodeVariableApplyToSetterNode();
224-
225-
$object = $this->getEncoderNodeVariableApplyToSetter();
226-
$parent = $this->getThing();
227-
$var = $node->getVariableById('node-full');
228-
229-
$this->assertEquals(array(
230-
'node' => 'test',
231-
'name' => 'node',
232-
'value' => 'test',
233-
'object' => $object,
234-
'parent' => $parent,
235-
), $var->applyToSetter(array(
236-
ActionVariable::SETTER_OBJECT => $object,
237-
ActionVariable::SETTER_PARENT => $parent,
238-
ActionVariable::SETTER_NODE_DATA => array(
239-
'node' => 'test'
240-
),
241-
ActionVariable::SETTER_NODE => $node,
242-
ActionVariable::SETTER_NAME => 'node',
243-
ActionVariable::SETTER_VALUE => 'test'
244-
)));
245-
}
246-
247-
public function testApplyToSetterNodeWithoutVariables() {
248-
$this->_applyToSetterNodeWithoutVariables('node-without-variables');
249-
$this->_applyToSetterNodeWithoutVariables('node-without-variables-empty');
250-
$this->_applyToSetterNodeWithoutVariables('node-without-variables-null');
251-
}
252-
protected function _applyToSetterNodeWithoutVariables($variable)
253-
{
254-
$node = $this->getEncoderNodeVariableApplyToSetterNode();
255-
256-
$object = $this->getEncoderNodeVariableApplyToSetter();
257-
$var = $node->getVariableById($variable);
258-
259-
$this->assertEquals(array(
260-
'test' => 'altered',
261-
), $var->applyToSetter(array(
262-
ActionVariable::SETTER_OBJECT => $object,
263-
ActionVariable::SETTER_NODE_DATA => array(
264-
'test' => 'test'
265-
),
266-
ActionVariable::SETTER_NODE => $node,
267-
ActionVariable::SETTER_NAME => 'node',
268-
ActionVariable::SETTER_VALUE => 'test'
269-
)));
270-
271-
$this->assertNull($object->getVar());
272-
}
273-
274-
public function testApplyToSetterNodeUnknownVariable() {
275-
$this->setExpectedException('\\PE\\Exceptions\\EncoderNodeVariableException', 'Action variable id "unknown_variable" is not known');
276-
$node = $this->getEncoderNodeVariableApplyToSetterNode();
277-
278-
$object = $this->getEncoderNodeVariableApplyToSetter();
279-
$var = $node->getVariableById('node-unknown-variable');
280-
281-
$var->applyToSetter(array(
282-
ActionVariable::SETTER_OBJECT => $object,
283-
ActionVariable::SETTER_NODE_DATA => array(
284-
'node' => 'test'
285-
),
286-
ActionVariable::SETTER_NODE => $node,
287-
ActionVariable::SETTER_NAME => 'node',
288-
ActionVariable::SETTER_VALUE => 'test'
289-
));
290-
}
291-
292-
public function testApplyToSetterObjectWithSetterMethod() {
293-
$this->_applyToSetterObject('var');
294-
$this->_applyToSetterObject('object-using-setter-action');
295-
$this->_applyToSetterObject('object-using-setter-method');
296-
}
297-
298-
public function testApplyToSetterObjectWithUnknownSetterMethod() {
299-
$this->setExpectedException('\\PE\\Exceptions\\EncoderNodeVariableException', 'Method "unknownMethod" does not exist for class PE\Samples\Specials\EncoderNodeVariableApplyToSetter does not exist');
300-
$this->_applyToSetterObject('object-using-unknown-setter-method');
301-
}
302-
303-
protected function _applyToSetterObject($variable) {
304-
$node = $this->getEncoderNodeVariableApplyToSetterNode();
305-
306-
$object = $this->getEncoderNodeVariableApplyToSetter();
307-
$var = $node->getVariableById($variable);
308-
309-
$this->assertTrue($var->applyToSetter(array(
310-
ActionVariable::SETTER_OBJECT => $object,
311-
ActionVariable::SETTER_VALUE => 'test'
312-
)));
313-
$this->assertEquals('test', $object->getVar());
314-
}
315118
}

tests/PE/Tests/Variables/Types/ObjectSetterTest.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace PE\Tests\Variables\Types;
44

5-
use PE\Tests\AbstractPETest;
5+
use PE\Nodes\EncoderNodeVariable;
6+
use PE\Tests\Samples;
7+
use PE\Variables\Types\NodeAccessor;
68
use PE\Variables\Types\ObjectSetter;
79

8-
class ObjectSetterTest extends AbstractPETest
10+
class ObjectSetterTest extends Samples
911
{
1012

1113
protected function setUp()
@@ -53,14 +55,24 @@ public function testAlwaysExecute() {
5355

5456
public function testEncodeWithoutVariableGetterMethod()
5557
{
56-
$this->markTestIncomplete(
57-
'This test has not been implemented yet.'
58-
);
58+
$this->setExpectedException('\\PE\\Exceptions\\VariableTypeException', 'Method "setNonExistent" does not exist for class "PE\Tests\Variables\Types\ObjectSetterTestObject');
5959

60-
$this->setExpectedException('\\PE\\Exceptions\\VariableTypeException', 'Method "getNonExistent" does not exist for class "PE\Samples\Erroneous\NoVariableGetterMethod" does not exist');
60+
$objectSetter = $this->objectSetter();
61+
$objectSetter->setVariable(new EncoderNodeVariable('non-existent'));
6162

6263
$this->objectSetter()->apply(new ObjectSetterTestObject(), 'value');
6364
}
65+
66+
public function testApplyToSetterObjectWithSetterMethod() {
67+
$node = $this->getEncoderNodeVariableApplyToSetterNode();
68+
69+
$object = $this->getEncoderNodeVariableApplyToSetter();
70+
$collection = $node->getVariableCollection();
71+
$var = $collection->getVariableById('var');
72+
73+
$this->assertTrue($var->getObjectSetter()->apply($object, 'test'));
74+
$this->assertEquals('test', $object->getVar());
75+
}
6476
}
6577

6678
class ObjectSetterTestObject {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace PE\Tests\Variables\Types;
4+
5+
use PE\Tests\Samples;
6+
use PE\Variables\Types\NodeAccessor;
7+
use PE\Variables\Types\PostNodeGetter;
8+
use PE\Variables\Types\PostNodeSetter;
9+
10+
class PostNodeGetterTest extends Samples
11+
{
12+
protected function setUp()
13+
{
14+
parent::setUp();
15+
$this->_peApp = new PostNodeGetter('method');
16+
}
17+
18+
/**
19+
* @return PostNodeGetter
20+
*/
21+
protected function postNodeGetter()
22+
{
23+
return $this->_peApp;
24+
}
25+
26+
public function testConstructor()
27+
{
28+
$setter = new PostNodeGetter('method');
29+
$this->assertNotNull($setter);
30+
$this->assertTrue($setter instanceof PostNodeGetter);
31+
}
32+
33+
public function testCallNodeGetterAction() {
34+
$node = $this->getAccessorMethodActionTypeNodeNode();
35+
$variable = $node->getVariable('node');
36+
37+
$this->assertEquals(array(
38+
'node' => 'hello world',
39+
'special' => 'hello world getter',
40+
), $variable->getPostNodeGetter()->apply(array(
41+
NodeAccessor::VARIABLE_NODE => $node,
42+
NodeAccessor::VARIABLE_NODE_DATA => array(
43+
'node' => 'hello world',
44+
),
45+
NodeAccessor::VARIABLE_NAME => 'node'
46+
)));
47+
}
48+
}

0 commit comments

Comments
 (0)