Innmind /
Immutable
| 1 | <?php |
||
| 2 | declare(strict_types = 1); |
||
| 3 | |||
| 4 | namespace Tests\Innmind\Immutable\Monoid; |
||
| 5 | |||
| 6 | use Innmind\Immutable\{ |
||
| 7 | Monoid\Append, |
||
| 8 | Monoid, |
||
| 9 | Sequence, |
||
| 10 | }; |
||
| 11 | use PHPUnit\Framework\TestCase; |
||
| 12 | use Innmind\BlackBox\{ |
||
| 13 | PHPUnit\BlackBox, |
||
| 14 | Set, |
||
| 15 | }; |
||
| 16 | use Properties\Innmind\Immutable\Monoid as PMonoid; |
||
| 17 | |||
| 18 | class AppendTest extends TestCase |
||
| 19 | { |
||
| 20 | use BlackBox; |
||
| 21 | |||
| 22 | public function testInterface() |
||
| 23 | { |
||
| 24 | $this->assertInstanceOf(Monoid::class, Append::of()); |
||
| 25 | } |
||
| 26 | |||
| 27 | public function testCombine() |
||
| 28 | { |
||
| 29 | $sequence = Append::of()->combine( |
||
| 30 | Sequence::of(1, 3), |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 31 | Sequence::of(2, 4), |
||
| 32 | ); |
||
| 33 | |||
| 34 | $this->assertInstanceOf(Sequence::class, $sequence); |
||
| 35 | $this->assertSame( |
||
| 36 | [1, 3, 2, 4], |
||
| 37 | $sequence->toList(), |
||
| 38 | ); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @dataProvider properties |
||
| 43 | */ |
||
| 44 | public function testHoldProperty($property) |
||
| 45 | { |
||
| 46 | $this |
||
| 47 | ->forAll($property) |
||
| 48 | ->then(static function($property) { |
||
| 49 | $property->ensureHeldBy(Append::of()); |
||
| 50 | }); |
||
| 51 | } |
||
| 52 | |||
| 53 | public function testHoldProperties() |
||
| 54 | { |
||
| 55 | $this |
||
| 56 | ->forAll(PMonoid::properties($this->set(), $this->equals())) |
||
| 57 | ->then(static function($properties) { |
||
| 58 | $properties->ensureHeldBy(Append::of()); |
||
| 59 | }); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function properties(): iterable |
||
| 63 | { |
||
| 64 | foreach (PMonoid::list($this->set(), $this->equals()) as $property) { |
||
| 65 | yield [$property]; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | public function equals(): callable |
||
| 70 | { |
||
| 71 | return static fn($a, $b) => $a->equals($b); |
||
| 72 | } |
||
| 73 | |||
| 74 | private function set(): Set |
||
| 75 | { |
||
| 76 | return Set\Decorate::immutable( |
||
| 77 | static fn($values) => Sequence::of(...$values), |
||
| 78 | Set\Sequence::of(Set\AnyType::any()), |
||
| 79 | ); |
||
| 80 | } |
||
| 81 | } |
||
| 82 |