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 [`ArrayHasKeyWith` constraint](https://github.com/PhrozenByte/phpunit-array-asserts/blob/master/src/Constraint/ArrayHasKeyWith.php) asserts that an array has a given key and that its value passes another constraint.
120
120
121
-
Accepts both native arrays and `ArrayAccess` objects. The constraint (parameter `$constraint`) will fail if the key (parameter `$key`) doesn't exist in the array. The item's key and the constraint the value must pass are passed in the constructor.
121
+
Accepts both native arrays and `ArrayAccess` objects. The constraint (parameter `$constraint`) will fail if the key (parameter `$key`) doesn't exist in the array. The item's key, and the constraint the value must pass 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.
122
122
123
123
The `ArrayAssertsTrait` trait exposes two public methods for the `ArrayHasKeyWith` constraint: Use `ArrayAssertsTrait::assertArrayHasKeyWith()` to perform an assertion, and `ArrayAssertsTrait::arrayHasKeyWith()` to create a new instance of the `ArrayHasKeyWith` constraint.
124
124
@@ -127,16 +127,16 @@ The `ArrayAssertsTrait` trait exposes two public methods for the `ArrayHasKeyWit
127
127
```php
128
128
// using `\PhrozenByte\PHPUnitArrayAsserts\ArrayAssertsTrait` trait
129
129
ArrayAssertsTrait::assertArrayHasKeyWith(
130
-
string|int $key, // the key of the item to check
131
-
Constraint $constraint, // the constraint the item's value is applied to
132
-
array|ArrayAccess $array, // the array to check
133
-
string $message = '' // additional information about the test
130
+
string|int $key, // the key of the item to check
131
+
Constraint|mixed $constraint, // the constraint the item's value is applied to
132
+
array|ArrayAccess $array, // the array to check
133
+
string $message = '' // additional information about the test
134
134
);
135
135
136
136
// using new instance of `\PhrozenByte\PHPUnitArrayAsserts\Constraint\ArrayHasKeyWith`
137
137
new ArrayHasKeyWith(
138
138
string|int $key,
139
-
Constraint $constraint
139
+
Constraint|mixed $constraint
140
140
);
141
141
```
142
142
@@ -150,20 +150,20 @@ $data = [
150
150
];
151
151
152
152
// asserts that $data has the item `name` with the value "Arthur Dent"
0 commit comments