File tree 2 files changed +15
-17
lines changed
test/Integration/Mapper/Strategy
2 files changed +15
-17
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
namespace ScriptFUSION \Mapper \Strategy ;
3
3
4
- use ScriptFUSION \Mapper \Mapper ;
5
4
use ScriptFUSION \Mapper \Mapping ;
6
5
7
6
/**
8
7
* Walks a nested structure to the specified element in the same manner as Copy.
9
8
*/
10
9
class Walk extends Delegate
11
10
{
12
- /**
13
- * @var Copy
14
- */
15
- private $ copy ;
11
+ private $ path ;
16
12
17
13
/**
18
14
* @param Strategy|Mapping|array|mixed $expression Expression to walk.
@@ -23,18 +19,13 @@ public function __construct($expression, $path)
23
19
{
24
20
parent ::__construct ($ expression );
25
21
26
- $ this ->copy = new Copy ( $ path) ;
22
+ $ this ->path = $ path ;
27
23
}
28
24
29
25
public function __invoke ($ data , $ context = null )
30
26
{
31
- return call_user_func ($ this ->copy , parent ::__invoke ($ data , $ context ), $ context );
32
- }
33
-
34
- public function setMapper (Mapper $ mapper )
35
- {
36
- $ this ->copy ->setMapper ($ mapper );
27
+ $ copy = (new Copy ($ this ->delegate ($ this ->path , $ data , $ context )))->setMapper ($ this ->getMapper ());
37
28
38
- return parent ::setMapper ( $ mapper );
29
+ return $ copy ( parent ::__invoke ( $ data , $ context ), $ context );
39
30
}
40
31
}
Original file line number Diff line number Diff line change 2
2
namespace ScriptFUSIONTest \Integration \Mapper \Strategy ;
3
3
4
4
use ScriptFUSION \Mapper \Mapper ;
5
+ use ScriptFUSION \Mapper \Strategy \Copy ;
5
6
use ScriptFUSION \Mapper \Strategy \Walk ;
6
7
7
8
final class WalkTest extends \PHPUnit_Framework_TestCase
8
9
{
9
- public function testWalk ()
10
+ public function testWalkFixedPath ()
10
11
{
11
- /** @var Walk $walk */
12
12
$ walk = (new Walk (['foo ' => ['bar ' => 'baz ' ]], 'foo->bar ' ))
13
- ->setMapper (new Mapper )
14
- ;
13
+ ->setMapper (new Mapper );
15
14
16
15
self ::assertSame ('baz ' , $ walk ([]));
17
16
}
17
+
18
+ public function testWalkStrategyPath ()
19
+ {
20
+ $ walk = (new Walk (['bar ' => 'baz ' ], new Copy ('foo ' )))
21
+ ->setMapper (new Mapper );
22
+
23
+ self ::assertSame ('baz ' , $ walk (['foo ' => 'bar ' ]));
24
+ }
18
25
}
You can’t perform that action at this time.
0 commit comments