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

AssertResourceLinkage   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 5
c 0
b 0
f 0
dl 0
loc 28
rs 10
1
<?php
2
namespace VGirol\JsonApiAssert\Laravel\Asserts\Content;
3
4
use Illuminate\Database\Eloquent\Model;
5
use Illuminate\Support\Collection;
6
use VGirol\JsonApiAssert\Laravel\Factory\HelperFactory;
7
8
trait AssertResourceLinkage
9
{
10
    /**
11
     * Asserts that a resource object correspond to a given model.
12
     *
13
     * @param Model $expected
14
     * @param string $resourceType
15
     * @param array $json
16
     */
17
    public static function assertResourceIdentifierEqualsModel($expected, $resourceType, $json)
18
    {
19
        $expected = HelperFactory::create('resource-identifier', $expected, $resourceType)->toArray();
20
21
        static::assertResourceIdentifierEquals($expected, $json);
22
    }
23
24
    /**
25
     * Asserts that an array of resource objects correspond to a given collection.
26
     *
27
     * @param Collection $collection
28
     * @param string $resourceType
29
     * @param array $json
30
     */
31
    public static function assertResourceCollectionEqualsCollection($collection, $resourceType, $json)
32
    {
33
        $expected = HelperFactory::create('collection', $collection, $resourceType, false)->toArray();
34
35
        static::assertResourceCollectionEquals($expected, $json);
36
    }
37
}
38