Completed
Push — master ( 26993f...e2fb6c )
by Dmitry
02:58
created

MapperTest::testEntityInheritance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Test;
4
5
use Basis\Test;
6
use Basis\Test\Mapper;
7
use Basis\Test\Repository;
8
9
class MapperTest extends Test
10
{
11
    public $data = [
12
        'flow.tracker' => [
13
            [], // use id generator
14
        ],
15
        'flow.status' => [],
16
    ];
17
18
    public function testEntityInheritance()
19
    {
20
        $status = $this->create('flow.status', []);
21
        $this->create('flow.tracker', [
22
            'status' => $status // create reference for id
23
        ]);
24
        $data = $this->find('flow.tracker', [
25
            'status' => $status->id
26
        ]);
27
        $this->assertCount(1, $data);
28
    }
29
30
    public function testFakeMapper()
31
    {
32
        $this->assertCount(1, $this->find('flow.tracker'));
33
        $this->assertSame(1, $this->findOrFail('flow.tracker')->id);
34
        $this->assertNotNull($this->findOrFail('flow.tracker', 1));
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
        $this->assertNull($this->findOne('flow.tracker', 2));
0 ignored issues
show
Documentation introduced by
2 is of type integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
36
37
        $tracker = $this->create('flow.tracker', [ 'status' => 'ready', ]);
38
        $this->assertSame($tracker->status, 'ready');
39
        $this->assertSame($tracker->id, 2);
40
41
        $this->assertCount(2, $this->find('flow.tracker'));
42
        $this->assertCount(1, $this->find('flow.tracker', [ 'status' => 'ready' ]));
43
44
        $this->assertInstanceOf(Repository::class, $this->getRepository('flow.tracker'));
45
46
        $mapper = $this->getRepository('flow.tracker')->getMapper();
47
        $this->assertInstanceOf(Mapper::class, $mapper);
48
        $this->assertNotNull($mapper);
49
50
        $mapper->remove('tracker', [ 'id' => 1 ]);
51
        $this->assertCount(1, $this->find('flow.tracker'));
52
        $this->assertSame(2, $this->findOne('flow.tracker')->id);
53
        $tracker = $this->create('flow.tracker', [ 'status' => 'ready', ]);
54
        $this->assertSame($tracker->status, 'ready');
55
        $this->assertSame($tracker->id, 3);
56
        $this->assertCount(2, $this->find('flow.tracker'));
57
        $this->assertNotNull($this->findOrFail('flow.tracker', 3));
0 ignored issues
show
Documentation introduced by
3 is of type integer, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
59
        $this->create('flow.tracker', ['status' => 'draft']);
60
        $this->assertCount(3, $this->find('flow.tracker'));
61
62
        $this->remove('flow.tracker', ['status' => 'ready']);
63
        $this->assertCount(1, $this->find('flow.tracker'));
64
        $this->getRepository('flow.tracker')->remove($this->findOne('flow.tracker'));
65
66
        $this->assertCount(0, $this->find('flow.tracker'));
67
68
        $tracker = $this->create('flow.tracker', []);
69
        $tracker->status = 'ready';
70
        $tracker->save();
71
        $this->assertSame($tracker->id, 1);
72
73
        $tracker = $this->findOne('flow.tracker', [ 'status' => 'ready']);
74
        $this->assertSame($tracker->status, 'ready');
75
76
        $tracker = $this->findOrCreate('flow.tracker', [ 'id' => 27, 'author' => 'nekufa' ]);
77
        $this->assertNotNull($tracker);
78
        $this->assertSame($tracker->id, 27);
79
80
        $trackerByAuthor = $this->findOrCreate('flow.tracker', [ 'author' => 'nekufa' ]);
81
        $this->assertNotNull($trackerByAuthor);
82
        $this->assertSame($tracker, $trackerByAuthor);
83
    }
84
}