Skip to content

Commit 355cf73

Browse files
Copilotvoku
andauthored
Add test verifying key parameter is passed correctly in findKey closure
Agent-Logs-Url: https://github.com/voku/Arrayy/sessions/9727c001-36d7-4c06-865e-c0a76fd5012f Co-authored-by: voku <264695+voku@users.noreply.github.com>
1 parent e73bc9e commit 355cf73

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

tests/ArrayyTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,25 @@ public function testFindKey($array, $search, $result)
32623262
static::assertSame($result, $resultMatch, 'tested:' . \print_r($array, true));
32633263
}
32643264

3265+
public function testFindKeyWithKeyParameter()
3266+
{
3267+
// Verify that the key parameter is correctly passed to the closure
3268+
$array = ['a' => 10, 'b' => 20, 'c' => 30];
3269+
$arrayy = A::create($array);
3270+
3271+
// Find the key of the element whose key is 'b'
3272+
$closure = static function ($value, $key) {
3273+
return $key === 'b';
3274+
};
3275+
static::assertSame('b', $arrayy->findKey($closure));
3276+
3277+
// Find no element when key doesn't match
3278+
$closureNoMatch = static function ($value, $key) {
3279+
return $key === 'z';
3280+
};
3281+
static::assertFalse($arrayy->findKey($closureNoMatch));
3282+
}
3283+
32653284
/**
32663285
* @dataProvider firstProvider()
32673286
*

0 commit comments

Comments
 (0)