1 | <?php |
||
2 | declare(strict_types = 1); |
||
3 | |||
4 | namespace Tests\Innmind\Immutable\Fixtures; |
||
5 | |||
6 | use Innmind\Immutable\Sequence as Structure; |
||
7 | use Innmind\BlackBox\Set; |
||
8 | use Fixtures\Innmind\Immutable\Sequence; |
||
9 | use PHPUnit\Framework\TestCase; |
||
10 | |||
11 | class SequenceTest extends TestCase |
||
12 | { |
||
13 | public function testInterface() |
||
14 | { |
||
15 | $this->assertInstanceOf( |
||
16 | Set::class, |
||
17 | new Sequence('string', new Set\Chars) |
||
0 ignored issues
–
show
|
|||
18 | ); |
||
19 | } |
||
20 | |||
21 | public function testOf() |
||
22 | { |
||
23 | $this->assertInstanceOf( |
||
24 | Sequence::class, |
||
25 | Sequence::of('string', new Set\Chars) |
||
26 | ); |
||
27 | } |
||
28 | |||
29 | public function testGenerates100ValuesByDefault() |
||
30 | { |
||
31 | $sequences = new Sequence('string', new Set\Chars); |
||
32 | |||
33 | $this->assertInstanceOf(\Generator::class, $sequences->values()); |
||
34 | $this->assertCount(100, \iterator_to_array($sequences->values())); |
||
35 | |||
36 | foreach ($sequences->values() as $sequence) { |
||
37 | $this->assertInstanceOf(Set\Value::class, $sequence); |
||
0 ignored issues
–
show
The type
Innmind\BlackBox\Set\Value was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
38 | $this->assertInstanceOf(Structure::class, $sequence->unwrap()); |
||
39 | $this->assertSame('string', (string) $sequence->unwrap()->type()); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | public function testGeneratesSequencesOfDifferentSizes() |
||
44 | { |
||
45 | $sequences = new Sequence( |
||
46 | 'string', |
||
47 | new Set\Chars, |
||
48 | Set\Integers::between(0, 50) |
||
0 ignored issues
–
show
The type
Innmind\BlackBox\Set\Integers was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
49 | ); |
||
50 | $sizes = []; |
||
51 | |||
52 | foreach ($sequences->values() as $sequence) { |
||
53 | $sizes[] = $sequence->unwrap()->size(); |
||
54 | } |
||
55 | |||
56 | $this->assertTrue(\count(\array_unique($sizes)) > 1); |
||
57 | } |
||
58 | |||
59 | public function testTake() |
||
60 | { |
||
61 | $sequences1 = new Sequence('string', new Set\Chars); |
||
62 | $sequences2 = $sequences1->take(50); |
||
63 | |||
64 | $this->assertNotSame($sequences1, $sequences2); |
||
65 | $this->assertInstanceOf(Sequence::class, $sequences2); |
||
66 | $this->assertCount(100, \iterator_to_array($sequences1->values())); |
||
67 | $this->assertCount(50, \iterator_to_array($sequences2->values())); |
||
68 | } |
||
69 | |||
70 | public function testFilter() |
||
71 | { |
||
72 | $sequences = new Sequence('string', new Set\Chars); |
||
73 | |||
74 | $this->expectException(\LogicException::class); |
||
75 | $this->expectExceptionMessage('Sequence set can\'t be filtered, underlying set must be filtered beforehand'); |
||
76 | |||
77 | $sequences->filter(static function($sequence): bool { |
||
78 | return $sequence->size() % 2 === 0; |
||
79 | }); |
||
80 | } |
||
81 | |||
82 | public function testFlagStructureAsMutableWhenUnderlyingSetValuesAreMutable() |
||
83 | { |
||
84 | $sequences = new Sequence( |
||
85 | 'object', |
||
86 | Set\Decorate::mutable( |
||
0 ignored issues
–
show
The type
Innmind\BlackBox\Set\Decorate was not found. Maybe you did not declare it correctly or list all dependencies?
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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths
Loading history...
|
|||
87 | fn() => new \stdClass, |
||
88 | new Set\Chars, |
||
89 | ), |
||
90 | ); |
||
91 | |||
92 | foreach ($sequences->values() as $sequence) { |
||
93 | $this->assertFalse($sequence->isImmutable()); |
||
94 | $this->assertNotSame($sequence->unwrap(), $sequence->unwrap()); |
||
95 | $this->assertSame($sequence->unwrap()->size(), $sequence->unwrap()->size()); |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 |
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