UtilsTest::testEnsureArray_AlreadyArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Gurucomkz\EagerLoading\Tests;
4
5
use Gurucomkz\EagerLoading\Utils;
6
use SilverStripe\Dev\SapphireTest;
7
8
class UtilsTest extends SapphireTest
9
{
10
    public function testEnsureArray_AlreadyArray()
11
    {
12
        $in = [1, 2, 3];
13
        $out = Utils::EnsureArray($in);
14
15
        $this->assertEquals($in, $out);
16
    }
17
18
    public function testEnsureArray_Object()
19
    {
20
        $o1 = (object) [
21
            'id' => 123,
22
            'title' => 'title1',
23
        ];
24
        $o2 = (object) [
25
            'id' => 234,
26
            'title' => 'title2',
27
        ];
28
        $o3 = (object) [
29
            'id' => 345,
30
            'title' => 'title3',
31
        ];
32
        $in = (object) [$o1, $o2, $o3];
33
        $out = Utils::EnsureArray($in, 'id');
34
35
        $expect = [
36
            123 => $o1,
37
            234 => $o2,
38
            345 => $o3,
39
        ];
40
        $this->assertEquals($expect, $out);
41
    }
42
}
43