File tree Expand file tree Collapse file tree 2 files changed +15
-17
lines changed
test/Integration/Mapper/Strategy Expand file tree Collapse file tree 2 files changed +15
-17
lines changed Original file line number Diff line number Diff line change 11<?php
22namespace ScriptFUSION \Mapper \Strategy ;
33
4- use ScriptFUSION \Mapper \Mapper ;
54use ScriptFUSION \Mapper \Mapping ;
65
76/**
87 * Walks a nested structure to the specified element in the same manner as Copy.
98 */
109class Walk extends Delegate
1110{
12- /**
13- * @var Copy
14- */
15- private $ copy ;
11+ private $ path ;
1612
1713 /**
1814 * @param Strategy|Mapping|array|mixed $expression Expression to walk.
@@ -23,18 +19,13 @@ public function __construct($expression, $path)
2319 {
2420 parent ::__construct ($ expression );
2521
26- $ this ->copy = new Copy ( $ path) ;
22+ $ this ->path = $ path ;
2723 }
2824
2925 public function __invoke ($ data , $ context = null )
3026 {
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 ());
3728
38- return parent ::setMapper ( $ mapper );
29+ return $ copy ( parent ::__invoke ( $ data , $ context ), $ context );
3930 }
4031}
Original file line number Diff line number Diff line change 22namespace ScriptFUSIONTest \Integration \Mapper \Strategy ;
33
44use ScriptFUSION \Mapper \Mapper ;
5+ use ScriptFUSION \Mapper \Strategy \Copy ;
56use ScriptFUSION \Mapper \Strategy \Walk ;
67
78final class WalkTest extends \PHPUnit_Framework_TestCase
89{
9- public function testWalk ()
10+ public function testWalkFixedPath ()
1011 {
11- /** @var Walk $walk */
1212 $ walk = (new Walk (['foo ' => ['bar ' => 'baz ' ]], 'foo->bar ' ))
13- ->setMapper (new Mapper )
14- ;
13+ ->setMapper (new Mapper );
1514
1615 self ::assertSame ('baz ' , $ walk ([]));
1716 }
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+ }
1825}
You can’t perform that action at this time.
0 commit comments