4 * @group GlobalFunctions
5 * @covers ::wfArrayFilter
6 * @covers ::wfArrayFilterByKey
8 class WfArrayFilterTest
extends \PHPUnit\Framework\TestCase
{
9 public function testWfArrayFilter() {
10 $arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
11 $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
14 $this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
16 $arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
17 $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
20 $this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
22 $arr = [ 'a', 'b', 'c' ];
23 $filtered = wfArrayFilter( $arr, function ( $val, $key ) {
26 $this->assertSame( [ 1 => 'b', 2 => 'c' ], $filtered );
29 public function testWfArrayFilterByKey() {
30 $arr = [ 'a' => 1, 'b' => 2, 'c' => 3 ];
31 $filtered = wfArrayFilterByKey( $arr, function ( $key ) {
34 $this->assertSame( [ 'a' => 1, 'c' => 3 ], $filtered );
36 $arr = [ 'a', 'b', 'c' ];
37 $filtered = wfArrayFilterByKey( $arr, function ( $key ) {
40 $this->assertSame( [ 1 => 'b', 2 => 'c' ], $filtered );