|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Jasny\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use function Jasny\iterable_concat; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* @covers \Jasny\iterable_concat |
|
10
|
|
|
*/ |
|
11
|
|
|
class IterableConcatTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
use ProvideIterablesTrait; |
|
14
|
|
|
|
|
15
|
|
|
public function provider() |
|
16
|
|
|
{ |
|
17
|
|
|
return $this->provideIterables(['a', 'b', 'c', 'd'], true); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @dataProvider provider |
|
22
|
|
|
*/ |
|
23
|
|
|
public function test($values) |
|
24
|
|
|
{ |
|
25
|
|
|
$result = iterable_concat($values); |
|
26
|
|
|
|
|
27
|
|
|
$this->assertEquals('abcd', $result); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testMixed() |
|
31
|
|
|
{ |
|
32
|
|
|
$bind = new class() { |
|
33
|
|
|
public function __toString(): string |
|
34
|
|
|
{ |
|
35
|
|
|
return 'bind'; |
|
36
|
|
|
} |
|
37
|
|
|
}; |
|
38
|
|
|
|
|
39
|
|
|
$values = [1, 'ring', 2, $bind]; |
|
40
|
|
|
$iterator = new \ArrayIterator($values); |
|
41
|
|
|
|
|
42
|
|
|
$result = iterable_concat($iterator); |
|
43
|
|
|
|
|
44
|
|
|
$this->assertEquals('1ring2bind', $result); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGlue() |
|
48
|
|
|
{ |
|
49
|
|
|
$values = ['one', 'ring', 'to', 'bind']; |
|
50
|
|
|
$iterator = new \ArrayIterator($values); |
|
51
|
|
|
|
|
52
|
|
|
$result = iterable_concat($iterator, '<->'); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertEquals('one<->ring<->to<->bind', $result); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testEmpty() |
|
58
|
|
|
{ |
|
59
|
|
|
$result = iterable_concat(new \EmptyIterator()); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEquals('', $result); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|