Completed
Branch develop (c4bcdd)
by Stephen
06:03
created

TransformableCollectionTest.php ➔ class_exists()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Spinen\Transformers;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Spinen\Transformers\TestCase;
7
use Spinen\Transformers\TransformableCollection;
8
use Spinen\Transformers\Transformer;
9
10
class TransformableCollectionTest extends TestCase
11
{
12
    /**
13
     * @var TransformableCollection
14
     */
15
    protected $collection;
16
17
    public function setUp()
18
    {
19
        parent::setUp();
20
21
        $this->collection = new TransformableCollection();
22
    }
23
24
    /**
25
     * @test
26
     * @group unit
27
     */
28
    public function it_builds_the_expected_path_the_the_transformer_for_short_name()
29
    {
30
        $this->assertEquals('Spinen\Transformers\Transformer', $this->collection->getTransformerClass('Transformer'));
31
    }
32
33
    /**
34
     * @test
35
     * @expectedException \Spinen\Transformers\Exceptions\TransformerNotFoundException
36
     * @group unit
37
     */
38
    public function it_raises_exception_when_the_transformer_does_not_exist()
39
    {
40
        $this->collection->transformToWithPagination('InvalidTransformer');
41
    }
42
43
    /**
44
     * @test
45
     * @group unit
46
     */
47
    public function it_allows_transformation()
48
    {
49
        $this->assertArrayHasKey('data', $this->collection->transformTo('TestUser'));
50
    }
51
52
    /**
53
     * @test
54
     * @group unit
55
     */
56
    public function it_allows_transformation_with_pagination()
57
    {
58
        $this->collection = $this->collection->transformToWithPagination('TestUser')
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->collection->trans...('TestUser')->toArray() of type array<string,integer|str...ouble","data":"array"}> is incompatible with the declared type object<Spinen\Transforme...ransformableCollection> of property $collection.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
59
                                             ->toArray();
60
        $this->assertArrayHasKey('data', $this->collection);
61
        $this->assertArrayHasKey('total', $this->collection);
62
    }
63
}
64
65
function class_exists($class)
66
{
67
    if (("Spinen\\Transformers\\InvalidTransformer" == $class) || ("InvalidTransformer" == $class)) {
68
        return false;
69
    }
70
71
    return true;
72
}
73
74
/**
75
 * Fake transformer to test the changes
76
 *
77
 * @package App\Support\Transformation\Stubs
78
 */
79
class TestUser extends Transformer
80
{
81
    /**
82
     * @param Model $model
83
     *
84
     * @return array
85
     */
86
    public function transform(Model $model)
87
    {
88
        return [];
89
    }
90
}
91