Passed
Push — master ( fc7811...360d9f )
by Alexander
05:14
created

ArrayHelperTest::testPermuting()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
4
namespace Horat1us\Yii\Tests\Helpers;
5
6
7
use Horat1us\Yii\Helpers\ArrayHelper;
8
use Horat1us\Yii\Tests\AbstractTestCase;
9
10
/**
11
 * Class ArrayHelperTest
12
 * @package Horat1us\Yii\Tests\Helpers
13
 *
14
 * @internal
15
 */
16
class ArrayHelperTest extends AbstractTestCase
17
{
18
    public function testPermuting()
19
    {
20
        $input = ['a', 'b',];
21
        $output = ArrayHelper::permute($input);
22
        $this->assertCount(2, $output);
23
        $this->assertEquals(['a', 'b',], $output[0]);
24
        $this->assertEquals(['b', 'a',], $output[1]);
25
    }
26
27
    public function testSome()
28
    {
29
        $array = [1, 2, 3];
30
31
        $arrayHas2 = ArrayHelper::some($array, function (int $item) {
32
            return $item === 2;
33
        });
34
        $this->assertTrue($arrayHas2);
35
36
        $arrayDoesNotHave4 = ArrayHelper::some($array, function (int $item) {
37
            return $item === 4;
38
        });
39
        $this->assertFalse($arrayDoesNotHave4);
40
    }
41
42
    public function testEvery()
43
    {
44
        $array = [1, 2, 3];
45
46
        $isIntegerArray = ArrayHelper::every($array, 'is_int');
47
        $this->assertTrue($isIntegerArray);
48
49
        $isStringArray = ArrayHelper::every($array, 'is_string');
50
        $this->assertFalse($isStringArray);
51
    }
52
}
53