You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The [`ArrayHasItemWith` constraint](https://github.com/PhrozenByte/phpunit-array-asserts/blob/master/src/Constraint/ArrayHasItemWith.php) asserts that an array has a item at a given index and that its value passes another constraint.
231
231
232
-
Accepts both native arrays and `Traversable` objects. The constraint will fail if the array has less items than required. The index of the item to check (parameter `$index`), and the constraint its value must pass (parameter `$constraint`) are passed in the constructor.
232
+
Accepts both native arrays and `Traversable` objects. The constraint will fail if the array has less items than required. The index of the item to check (parameter `$index`), and the constraint its value must pass (parameter `$constraint`) are passed in the constructor. The constraint can either be an arbitrary `Constraint` instance (e.g. `PHPUnit\Framework\Constraint\StringContains`), or any static value, requiring an exact match of the value.
233
233
234
234
This constraint will fully traverse any `Traversable` object given. This also means that any `Generator` will be fully exhausted. It doesn't restore an `Iterator`'s pointer to its previous state.
235
235
@@ -240,16 +240,16 @@ The `ArrayAssertsTrait` trait exposes two public methods for the `ArrayHasItemWi
240
240
```php
241
241
// using `\PhrozenByte\PHPUnitArrayAsserts\ArrayAssertsTrait` trait
242
242
ArrayAssertsTrait::assertArrayHasItemWith(
243
-
int $index, // the index of the item to check
244
-
Constraint $constraint, // the constraint the item's value is applied to
245
-
array|Traversable $array, // the array to check
246
-
string $message = '' // additional information about the test
243
+
int $index, // the index of the item to check
244
+
Constraint|mixed $constraint, // the constraint the item's value is applied to
245
+
array|Traversable $array, // the array to check
246
+
string $message = '' // additional information about the test
247
247
);
248
248
249
249
// using new instance of `\PhrozenByte\PHPUnitArrayAsserts\Constraint\ArrayHasItemWith`
250
250
new ArrayHasItemWith(
251
251
int $index,
252
-
Constraint $constraint
252
+
Constraint|mixed $constraint
253
253
);
254
254
```
255
255
@@ -266,20 +266,20 @@ $data = [
266
266
];
267
267
268
268
// asserts that `$data` contains "Life, the Universe and Everything" as third item (i.e. at index 2)
269
-
$this->assertArrayHasItemWith(2, $this->identicalTo("Life, the Universe and Everything"));
269
+
$this->assertArrayHasItemWith(2, "Life, the Universe and Everything");
0 commit comments