|
9 | 9 |
|
10 | 10 | trait Matching
|
11 | 11 | {
|
12 |
| - /** |
13 |
| - * Assets that all values exist and match their expected values. |
14 |
| - * |
15 |
| - * @param string $key |
16 |
| - * @param array|string $expected |
17 |
| - * |
18 |
| - * @return $this |
19 |
| - */ |
20 |
| - public function whereHas(string $key, $expected) |
21 |
| - { |
22 |
| - $actual = Collection::make( |
23 |
| - $this->prop($key) ?? $this->prop() |
24 |
| - ); |
25 |
| - |
26 |
| - $missing = Collection::make($expected)->reject(function ($search) use ($key, $actual) { |
27 |
| - if ($actual->containsStrict($key, $search)) { |
28 |
| - return true; |
29 |
| - } |
30 |
| - |
31 |
| - return $actual->containsStrict($search); |
32 |
| - })->toArray(); |
33 |
| - |
34 |
| - $values = array_values($missing); |
35 |
| - |
36 |
| - PHPUnit::assertEmpty( |
37 |
| - $missing, |
38 |
| - sprintf( |
39 |
| - 'Property [%s] does not contain [%s].', |
40 |
| - $key, |
41 |
| - implode(', ', $values) |
42 |
| - ) |
43 |
| - ); |
44 |
| - |
45 |
| - return $this; |
46 |
| - } |
47 |
| - |
48 | 12 | /**
|
49 | 13 | * Asserts that the property matches the expected value.
|
50 | 14 | *
|
@@ -139,6 +103,42 @@ public function whereAllType(array $bindings): self
|
139 | 103 | return $this;
|
140 | 104 | }
|
141 | 105 |
|
| 106 | + /** |
| 107 | + * Asserts that all values exist and match their expected values. |
| 108 | + * |
| 109 | + * @param string $key |
| 110 | + * @param array|string $expected |
| 111 | + * |
| 112 | + * @return $this |
| 113 | + */ |
| 114 | + public function whereHas(string $key, $expected) |
| 115 | + { |
| 116 | + $actual = Collection::make( |
| 117 | + $this->prop($key) ?? $this->prop() |
| 118 | + ); |
| 119 | + |
| 120 | + $missing = Collection::make($expected)->reject(function ($search) use ($key, $actual) { |
| 121 | + if ($actual->containsStrict($key, $search)) { |
| 122 | + return true; |
| 123 | + } |
| 124 | + |
| 125 | + return $actual->containsStrict($search); |
| 126 | + })->toArray(); |
| 127 | + |
| 128 | + $values = array_values($missing); |
| 129 | + |
| 130 | + PHPUnit::assertEmpty( |
| 131 | + $missing, |
| 132 | + sprintf( |
| 133 | + 'Property [%s] does not contain [%s].', |
| 134 | + $key, |
| 135 | + implode(', ', $values) |
| 136 | + ) |
| 137 | + ); |
| 138 | + |
| 139 | + return $this; |
| 140 | + } |
| 141 | + |
142 | 142 | /**
|
143 | 143 | * Ensures that all properties are sorted the same way, recursively.
|
144 | 144 | *
|
|
0 commit comments