|
16 | 16 | use ArrayIterator; |
17 | 17 | use PHPUnit\Framework\Attributes\CoversClass; |
18 | 18 | use PHPUnit\Framework\Attributes\DataProvider; |
| 19 | +use PHPUnit\Framework\Attributes\Test; |
19 | 20 | use PHPUnit\Framework\TestCase; |
20 | 21 | use stdClass; |
21 | 22 | use TypeError; |
@@ -172,4 +173,36 @@ public function testItCanReplaceItsValueWithThatOfAnotherInstance(): void |
172 | 173 | self::assertEquals($expected, $bag->replace($defaultBag)); |
173 | 174 | self::assertEquals($defaultBag, $defaultBag->replace($bag)); |
174 | 175 | } |
| 176 | + |
| 177 | + #[Test] |
| 178 | + public function it_can_evaluate_if_the_bag_is_identical(): void |
| 179 | + { |
| 180 | + $bag = new VariableBag([ |
| 181 | + 'foo' => 'bar', |
| 182 | + 'yolo' => 42, |
| 183 | + 'list' => 'this is a list', |
| 184 | + ]); |
| 185 | + |
| 186 | + self::assertFalse($bag->equals(new ArrayIterator())); |
| 187 | + self::assertFalse($bag->equals(new stdClass())); |
| 188 | + self::assertFalse($bag->equals('bag')); |
| 189 | + self::assertFalse($bag->equals(new VariableBag())); |
| 190 | + self::assertTrue($bag->equals($bag)); |
| 191 | + } |
| 192 | + |
| 193 | + #[Test] |
| 194 | + public function it_can_filter_its_content(): void |
| 195 | + { |
| 196 | + $bag = new VariableBag([ |
| 197 | + 'foo' => 'bar', |
| 198 | + 'yolo' => 42, |
| 199 | + 'list' => 'this is a list', |
| 200 | + ]); |
| 201 | + self::assertCount(3, $bag); |
| 202 | + |
| 203 | + $newBag = $bag->filter(fn ($value, $key) => 'foo' === $key); |
| 204 | + |
| 205 | + self::assertFalse($newBag->equals($bag)); |
| 206 | + self::assertCount(1, $newBag); |
| 207 | + } |
175 | 208 | } |
0 commit comments