File tree Expand file tree Collapse file tree 5 files changed +53
-9
lines changed
Integration/Mapper/Strategy Expand file tree Collapse file tree 5 files changed +53
-9
lines changed Original file line number Diff line number Diff line change 1010 - 7.0
1111 - 7.1
1212 - 7.2
13+ - 7.3
1314
1415env :
1516 matrix :
@@ -21,16 +22,16 @@ matrix:
2122
2223cache :
2324 directories :
24- - .composer/cache
25+ - vendor
2526
2627install :
2728 - alias composer=composer\ -n && composer selfupdate
2829 - composer validate
29- - composer update $DEPENDENCIES
30+ - composer update --no-progress --no-suggest $DEPENDENCIES
3031
3132script :
3233 - composer test -- --coverage-clover=build/logs/clover.xml
3334
3435after_success :
35- - composer require satooshi /php-coveralls
36- - vendor/bin/coveralls -v
36+ - composer require php-coveralls /php-coveralls:^2
37+ - vendor/bin/php- coveralls -v
Original file line number Diff line number Diff line change @@ -682,7 +682,7 @@ $data = ['foo' => 'foo'];
682682
683683### Join
684684
685- Joins sub-string expressions together with a glue string.
685+ Joins expressions together with a glue string.
686686
687687#### Signature
688688
@@ -691,7 +691,7 @@ Join(string $glue, array ...$expressions)
691691```
692692
693693 1 . ` $glue ` &ndash ; Glue.
694- 2 . ` $expressions ` &ndash ; Sub-string expressions .
694+ 2 . ` $expressions ` &ndash ; Expressions to join or a single expression that resolves to an array to join .
695695
696696#### Example
697697
@@ -704,6 +704,15 @@ Join(string $glue, array ...$expressions)
704704
705705> 'foo-bar'
706706
707+ ``` php
708+ (new Mapper)->map(
709+ ['foo' => ['bar', 'baz']],
710+ new Join('-', new Copy('foo'))
711+ );
712+ ```
713+
714+ > 'bar-baz'
715+
707716### Merge
708717
709718Merges two data sets together giving precedence to the latter if string keys collide; integer keys never collide. For more information see [ array_merge] ( http://php.net/manual/en/function.array-merge.php ) .
Original file line number Diff line number Diff line change @@ -9,10 +9,10 @@ class Join extends Delegate
99 private $ glue ;
1010
1111 /**
12- * Initializes this instance with the specified glue to join the specified sub-strings together.
12+ * Initializes this instance with the specified glue to join the specified expressions together.
1313 *
1414 * @param string $glue Glue.
15- * @param array ...$expressions Sub-string expressions .
15+ * @param array ...$expressions Expressions to join or a single expression that resolves to an array to join .
1616 */
1717 public function __construct ($ glue , ...$ expressions )
1818 {
@@ -23,6 +23,13 @@ public function __construct($glue, ...$expressions)
2323
2424 public function __invoke ($ data , $ context = null )
2525 {
26- return implode ($ this ->glue , parent ::__invoke ($ data , $ context ));
26+ $ pieces = parent ::__invoke ($ data , $ context );
27+
28+ if (count ($ pieces ) === 1 && is_array ($ pieces [0 ])) {
29+ // Unwrap.
30+ $ pieces = $ pieces [0 ];
31+ }
32+
33+ return implode ($ this ->glue , $ pieces );
2734 }
2835}
Original file line number Diff line number Diff line change @@ -281,6 +281,14 @@ public function testJoin()
281281 new Join ('- ' , new Copy ('foo ' ), 'bar ' )
282282 )
283283 );
284+
285+ self ::assertSame (
286+ 'bar-baz ' ,
287+ (new Mapper )->map (
288+ ['foo ' => ['bar ' , 'baz ' ]],
289+ new Join ('- ' , new Copy ('foo ' ))
290+ )
291+ );
284292 }
285293
286294 public function testMerge ()
Original file line number Diff line number Diff line change 11<?php
22namespace ScriptFUSIONTest \Integration \Mapper \Strategy ;
33
4+ use Mockery \Adapter \Phpunit \MockeryPHPUnitIntegration ;
45use ScriptFUSION \Mapper \Mapper ;
56use ScriptFUSION \Mapper \Strategy \Join ;
67use ScriptFUSION \Mapper \Strategy \Strategy ;
78
89final class JoinTest extends \PHPUnit_Framework_TestCase
910{
11+ use MockeryPHPUnitIntegration;
12+
13+ /**
14+ * Tests that multiple expression are joined.
15+ */
1016 public function testJoin ()
1117 {
1218 $ join = (new Join (
@@ -17,4 +23,17 @@ public function testJoin()
1723
1824 self ::assertSame ('foo-bar ' , $ join ([]));
1925 }
26+
27+ /**
28+ * Tests that a single expression evaluating to an array is joined.
29+ */
30+ public function testJoinArray ()
31+ {
32+ $ join = (new Join (
33+ '- ' ,
34+ ['foo ' , 'bar ' ]
35+ ))->setMapper (new Mapper );
36+
37+ self ::assertSame ('foo-bar ' , $ join ([]));
38+ }
2039}
You can’t perform that action at this time.
0 commit comments