File tree 5 files changed +53
-9
lines changed
Integration/Mapper/Strategy
5 files changed +53
-9
lines changed Original file line number Diff line number Diff line change 10
10
- 7.0
11
11
- 7.1
12
12
- 7.2
13
+ - 7.3
13
14
14
15
env :
15
16
matrix :
@@ -21,16 +22,16 @@ matrix:
21
22
22
23
cache :
23
24
directories :
24
- - .composer/cache
25
+ - vendor
25
26
26
27
install :
27
28
- alias composer=composer\ -n && composer selfupdate
28
29
- composer validate
29
- - composer update $DEPENDENCIES
30
+ - composer update --no-progress --no-suggest $DEPENDENCIES
30
31
31
32
script :
32
33
- composer test -- --coverage-clover=build/logs/clover.xml
33
34
34
35
after_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'];
682
682
683
683
### Join
684
684
685
- Joins sub-string expressions together with a glue string.
685
+ Joins expressions together with a glue string.
686
686
687
687
#### Signature
688
688
@@ -691,7 +691,7 @@ Join(string $glue, array ...$expressions)
691
691
```
692
692
693
693
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 .
695
695
696
696
#### Example
697
697
@@ -704,6 +704,15 @@ Join(string $glue, array ...$expressions)
704
704
705
705
> 'foo-bar'
706
706
707
+ ``` php
708
+ (new Mapper)->map(
709
+ ['foo' => ['bar', 'baz']],
710
+ new Join('-', new Copy('foo'))
711
+ );
712
+ ```
713
+
714
+ > 'bar-baz'
715
+
707
716
### Merge
708
717
709
718
Merges 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
9
9
private $ glue ;
10
10
11
11
/**
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.
13
13
*
14
14
* @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 .
16
16
*/
17
17
public function __construct ($ glue , ...$ expressions )
18
18
{
@@ -23,6 +23,13 @@ public function __construct($glue, ...$expressions)
23
23
24
24
public function __invoke ($ data , $ context = null )
25
25
{
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 );
27
34
}
28
35
}
Original file line number Diff line number Diff line change @@ -281,6 +281,14 @@ public function testJoin()
281
281
new Join ('- ' , new Copy ('foo ' ), 'bar ' )
282
282
)
283
283
);
284
+
285
+ self ::assertSame (
286
+ 'bar-baz ' ,
287
+ (new Mapper )->map (
288
+ ['foo ' => ['bar ' , 'baz ' ]],
289
+ new Join ('- ' , new Copy ('foo ' ))
290
+ )
291
+ );
284
292
}
285
293
286
294
public function testMerge ()
Original file line number Diff line number Diff line change 1
1
<?php
2
2
namespace ScriptFUSIONTest \Integration \Mapper \Strategy ;
3
3
4
+ use Mockery \Adapter \Phpunit \MockeryPHPUnitIntegration ;
4
5
use ScriptFUSION \Mapper \Mapper ;
5
6
use ScriptFUSION \Mapper \Strategy \Join ;
6
7
use ScriptFUSION \Mapper \Strategy \Strategy ;
7
8
8
9
final class JoinTest extends \PHPUnit_Framework_TestCase
9
10
{
11
+ use MockeryPHPUnitIntegration;
12
+
13
+ /**
14
+ * Tests that multiple expression are joined.
15
+ */
10
16
public function testJoin ()
11
17
{
12
18
$ join = (new Join (
@@ -17,4 +23,17 @@ public function testJoin()
17
23
18
24
self ::assertSame ('foo-bar ' , $ join ([]));
19
25
}
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
+ }
20
39
}
You can’t perform that action at this time.
0 commit comments