Skip to content

Commit 4ac214b

Browse files
committed
Use internal array_find_key impl
1 parent c6c0ba7 commit 4ac214b

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

tests/Phing/Test/Task/Optional/WikiPublishTaskTest.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,44 @@
2424
use Phing\Task\Ext\WikiPublishTask;
2525
use Phing\Test\Support\BuildFileTest;
2626
use PHPUnit\Framework\MockObject\MockObject;
27-
use function array_find_key;
2827

2928
/**
3029
* WikiPublish task test.
3130
*
3231
* @author Piotr Lewandowski <piotr@cassis.pl>
3332
*
3433
* @internal
34+
* @phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
3535
*/
3636
class WikiPublishTaskTest extends BuildFileTest
3737
{
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+
3865
public function testApiEdit(): void
3966
{
4067
$task = $this->getWikiPublishMock();
@@ -63,7 +90,7 @@ public function testApiEdit(): void
6390
$task->expects($this->exactly(count($callParams)))
6491
->method('callApi')
6592
->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 {
6794
return $value[0] === $action && ($value[1] ?? null) === $args;
6895
});
6996
if (isset($callParams[$index])) {

0 commit comments

Comments
 (0)