|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Tests\Innmind\Immutable\Fixtures; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Immutable\Map as Structure; |
|
7
|
|
|
use Innmind\BlackBox\Set; |
|
8
|
|
|
use Fixtures\Innmind\Immutable\Map; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
class MapTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
public function testInterface() |
|
14
|
|
|
{ |
|
15
|
|
|
$this->assertInstanceOf( |
|
16
|
|
|
Set::class, |
|
17
|
|
|
new Map( |
|
18
|
|
|
'string', |
|
19
|
|
|
'string', |
|
20
|
|
|
new Set\Chars, |
|
|
|
|
|
|
21
|
|
|
new Set\Chars |
|
22
|
|
|
) |
|
23
|
|
|
); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testOf() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->assertInstanceOf( |
|
29
|
|
|
Map::class, |
|
30
|
|
|
Map::of( |
|
31
|
|
|
'string', |
|
32
|
|
|
'string', |
|
33
|
|
|
new Set\Chars, |
|
34
|
|
|
new Set\Chars |
|
35
|
|
|
) |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testGenerates100ValuesByDefault() |
|
40
|
|
|
{ |
|
41
|
|
|
$maps = new Map( |
|
42
|
|
|
'string', |
|
43
|
|
|
'int', |
|
44
|
|
|
new Set\Chars, |
|
45
|
|
|
Set\Integers::any() |
|
|
|
|
|
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertInstanceOf(\Generator::class, $maps->values()); |
|
49
|
|
|
$this->assertCount(100, \iterator_to_array($maps->values())); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($maps->values() as $map) { |
|
52
|
|
|
$this->assertInstanceOf(Set\Value::class, $map); |
|
|
|
|
|
|
53
|
|
|
$this->assertInstanceOf(Structure::class, $map->unwrap()); |
|
54
|
|
|
$this->assertSame('string', (string) $map->unwrap()->keyType()); |
|
55
|
|
|
$this->assertSame('int', (string) $map->unwrap()->valueType()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGeneratesSequencesOfDifferentSizes() |
|
60
|
|
|
{ |
|
61
|
|
|
$maps = new Map( |
|
62
|
|
|
'string', |
|
63
|
|
|
'string', |
|
64
|
|
|
new Set\Chars, |
|
65
|
|
|
new Set\Chars, |
|
66
|
|
|
Set\Integers::between(0, 50) |
|
67
|
|
|
); |
|
68
|
|
|
$sizes = []; |
|
69
|
|
|
|
|
70
|
|
|
foreach ($maps->values() as $map) { |
|
71
|
|
|
$sizes[] = $map->unwrap()->size(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$this->assertTrue(\count(\array_unique($sizes)) > 1); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testTake() |
|
78
|
|
|
{ |
|
79
|
|
|
$maps1 = new Map( |
|
80
|
|
|
'string', |
|
81
|
|
|
'string', |
|
82
|
|
|
new Set\Chars, |
|
83
|
|
|
new Set\Chars |
|
84
|
|
|
); |
|
85
|
|
|
$maps2 = $maps1->take(50); |
|
86
|
|
|
|
|
87
|
|
|
$this->assertNotSame($maps1, $maps2); |
|
88
|
|
|
$this->assertInstanceOf(Map::class, $maps2); |
|
89
|
|
|
$this->assertCount(100, \iterator_to_array($maps1->values())); |
|
90
|
|
|
$this->assertCount(50, \iterator_to_array($maps2->values())); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testFilter() |
|
94
|
|
|
{ |
|
95
|
|
|
$maps = new Map( |
|
96
|
|
|
'string', |
|
97
|
|
|
'string', |
|
98
|
|
|
new Set\Chars, |
|
99
|
|
|
new Set\Chars |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
$this->expectException(\LogicException::class); |
|
103
|
|
|
$this->expectExceptionMessage('Map set can\'t be filtered, underlying sets must be filtered beforehand'); |
|
104
|
|
|
|
|
105
|
|
|
$maps->filter(static function($map): bool { |
|
106
|
|
|
return $map->size() % 2 === 0; |
|
107
|
|
|
}); |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function testFlagStructureAsMutableWhenUnderlyingKeysAreMutable() |
|
111
|
|
|
{ |
|
112
|
|
|
$maps = new Map( |
|
113
|
|
|
'object', |
|
114
|
|
|
'string', |
|
115
|
|
|
Set\Decorate::mutable( |
|
|
|
|
|
|
116
|
|
|
fn() => new \stdClass, |
|
117
|
|
|
new Set\Chars, |
|
118
|
|
|
), |
|
119
|
|
|
new Set\Chars, |
|
120
|
|
|
); |
|
121
|
|
|
|
|
122
|
|
|
foreach ($maps->values() as $map) { |
|
123
|
|
|
$this->assertFalse($map->isImmutable()); |
|
124
|
|
|
$this->assertNotSame($map->unwrap(), $map->unwrap()); |
|
125
|
|
|
$this->assertSame($map->unwrap()->size(), $map->unwrap()->size()); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function testFlagStructureAsMutableWhenUnderlyingValuesAreMutable() |
|
130
|
|
|
{ |
|
131
|
|
|
$maps = new Map( |
|
132
|
|
|
'string', |
|
133
|
|
|
'object', |
|
134
|
|
|
new Set\Chars, |
|
135
|
|
|
Set\Decorate::mutable( |
|
136
|
|
|
fn() => new \stdClass, |
|
137
|
|
|
new Set\Chars, |
|
138
|
|
|
), |
|
139
|
|
|
); |
|
140
|
|
|
|
|
141
|
|
|
foreach ($maps->values() as $map) { |
|
142
|
|
|
$this->assertFalse($map->isImmutable()); |
|
143
|
|
|
$this->assertNotSame($map->unwrap(), $map->unwrap()); |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths