|
24 | 24 | use Phing\Task\Ext\WikiPublishTask; |
25 | 25 | use Phing\Test\Support\BuildFileTest; |
26 | 26 | use PHPUnit\Framework\MockObject\MockObject; |
27 | | -use function array_find_key; |
28 | 27 |
|
29 | 28 | /** |
30 | 29 | * WikiPublish task test. |
31 | 30 | * |
32 | 31 | * @author Piotr Lewandowski <piotr@cassis.pl> |
33 | 32 | * |
34 | 33 | * @internal |
| 34 | + * @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
35 | 35 | */ |
36 | 36 | class WikiPublishTaskTest extends BuildFileTest |
37 | 37 | { |
| 38 | + /** |
| 39 | + * Returns the KEY of the first element for which the $callback |
| 40 | + * returns TRUE. If no matching element is found the function |
| 41 | + * returns NULL. |
| 42 | + * |
| 43 | + * @param array $array The array that should be searched. |
| 44 | + * @param callable $callback The callback function to call to check |
| 45 | + * each element. The first parameter contains the value ($value), |
| 46 | + * the second parameter contains the corresponding key ($key). If |
| 47 | + * this function returns TRUE, the key ($key) is returned |
| 48 | + * immediately and the callback will not be called for further |
| 49 | + * elements. |
| 50 | + * |
| 51 | + * @return mixed The key of the first element for which the |
| 52 | + * $callback returns TRUE. NULL, If no matching element is found. |
| 53 | + */ |
| 54 | + private function array_find_key(array $array, callable $callback) |
| 55 | + { |
| 56 | + foreach ($array as $key => $value) { |
| 57 | + if ($callback($value, $key)) { |
| 58 | + return $key; |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + return null; |
| 63 | + } |
| 64 | + |
38 | 65 | public function testApiEdit(): void |
39 | 66 | { |
40 | 67 | $task = $this->getWikiPublishMock(); |
@@ -63,7 +90,7 @@ public function testApiEdit(): void |
63 | 90 | $task->expects($this->exactly(count($callParams))) |
64 | 91 | ->method('callApi') |
65 | 92 | ->willReturnCallback(function (string $action, array|null $args) use ($callParams, $returnResults): array { |
66 | | - $index = array_find_key($callParams, function (array $value) use ($action, $args): bool { |
| 93 | + $index = $this->array_find_key($callParams, function (array $value) use ($action, $args): bool { |
67 | 94 | return $value[0] === $action && ($value[1] ?? null) === $args; |
68 | 95 | }); |
69 | 96 | if (isset($callParams[$index])) { |
|
0 commit comments