Passed
Push — master ( fae453...efb6a4 )
by Vincent
02:44
created

CanCreate::modelFactory()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 14
c 0
b 0
f 0
dl 0
loc 22
rs 9.7998
cc 2
nc 2
nop 3
1
<?php
2
namespace VGirol\JsonApiAssert\Laravel\Tests\Factory;
3
4
use VGirol\JsonApiAssert\Laravel\Tests\Tools\Models\ModelForTest;
5
6
trait CanCreate
7
{
8
    public function modelFactory($type, $isRI, $i = 0)
9
    {
10
        $id = 100 + $i * 10;
11
        $attributes = [
12
            'TST_ID' => $id,
13
            'TST_NAME' => 'model #' . $i,
14
            'TST_NUMBER' => $i * 100 + $i * 5,
15
            'TST_CREATION_DATE' => '2019-01-0' . $i
16
        ];
17
18
        $expectedModel = [
19
            'type' => $type,
20
            'id' => strval($id)
21
        ];
22
        if (!$isRI) {
23
            $expectedModel['attributes'] = $attributes;
24
        }
25
26
        $model = new ModelForTest;
27
        $model->setRawAttributes($attributes);
28
29
        return [$model, $expectedModel];
30
    }
31
32
    protected function collectionFactory($count, $type, $isRI)
33
    {
34
        $expected = [];
35
        $collection = [];
36
        for ($i = 1; $i <= $count; $i++) {
37
            list($model, $expectedModel) = $this->modelFactory($type, $isRI, $i);
38
            array_push($expected, $expectedModel);
39
            array_push($collection, $model);
40
        }
41
42
        return [collect($collection), $expected];
43
    }
44
}
45