Passed
Push — master ( 82c6b4...8a83ac )
by Gabriel
03:56 queued 12s
created

RecordTraitTest::testHasPrimaryKeyComposite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 9
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 14
rs 9.9666
1
<?php
2
3
namespace Nip\Records\Tests\Traits\HasPrimaryKey;
4
5
use Nip\Database\Connections\Connection;
6
use Nip\Records\Record;
7
use Nip\Records\RecordManager as Records;
8
use Nip\Records\Tests\AbstractTest;
9
10
/**
11
 * Class RecordTest
12
 * @package Nip\Records\Tests\Traits\HasPrimaryKey
13
 */
14
class RecordTraitTest extends AbstractTest
15
{
16
    public function testGetPrimaryKeySimple()
17
    {
18
        $this->object->getManager()->setPrimaryKey('id');
0 ignored issues
show
Bug introduced by
It seems like setPrimaryKey() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

18
        $this->object->getManager()->/** @scrutinizer ignore-call */ setPrimaryKey('id');
Loading history...
19
        $this->object->id = 99;
20
21
        static::assertEquals('99', $this->object->getPrimaryKey());
22
    }
23
24
    public function testGetPrimaryKeyComposite()
25
    {
26
        $this->object->getManager()->setPrimaryKey(['id_parent', 'type']);
0 ignored issues
show
Bug introduced by
array('id_parent', 'type') of type array<integer,string> is incompatible with the type null|string expected by parameter $primaryKey of Nip\Records\AbstractMode...anager::setPrimaryKey(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

26
        $this->object->getManager()->setPrimaryKey(/** @scrutinizer ignore-type */ ['id_parent', 'type']);
Loading history...
27
        $this->object->id_parent = 99;
0 ignored issues
show
Bug Best Practice introduced by
The property id_parent does not exist on Nip\Records\Record. Since you implemented __set, consider adding a @property annotation.
Loading history...
28
        $this->object->type = 'book';
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist on Nip\Records\Record. Since you implemented __set, consider adding a @property annotation.
Loading history...
29
30
        static::assertEquals(['id_parent' => 99, 'type' => 'book'], $this->object->getPrimaryKey());
31
    }
32
33
    public function testHasPrimaryKeyComposite()
34
    {
35
        $this->object->getManager()->setPrimaryKey(['id_parent', 'type']);
0 ignored issues
show
Bug introduced by
array('id_parent', 'type') of type array<integer,string> is incompatible with the type null|string expected by parameter $primaryKey of Nip\Records\AbstractMode...anager::setPrimaryKey(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        $this->object->getManager()->setPrimaryKey(/** @scrutinizer ignore-type */ ['id_parent', 'type']);
Loading history...
36
        static::assertFalse($this->object->hasPrimaryKey());
37
38
        $this->object->id_parent = null;
0 ignored issues
show
Bug Best Practice introduced by
The property id_parent does not exist on Nip\Records\Record. Since you implemented __set, consider adding a @property annotation.
Loading history...
39
        $this->object->type = '';
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist on Nip\Records\Record. Since you implemented __set, consider adding a @property annotation.
Loading history...
40
        static::assertFalse($this->object->hasPrimaryKey());
41
42
        $this->object->id_parent = 0;
43
        static::assertFalse($this->object->hasPrimaryKey());
44
45
        $this->object->id_parent = 1;
46
        static::assertTrue($this->object->hasPrimaryKey());
47
    }
48
49
    protected function setUp()
50
    {
51
        parent::setUp();
52
        $wrapper = new Connection(false);
0 ignored issues
show
Bug introduced by
false of type false is incompatible with the type Closure|PDO expected by parameter $pdo of Nip\Database\Connections\Connection::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

52
        $wrapper = new Connection(/** @scrutinizer ignore-type */ false);
Loading history...
53
54
        $manager = new Records();
55
        $manager->setDB($wrapper);
56
        $manager->setTable('pages');
57
58
        $this->object = new Record();
59
        $this->object->setManager($manager);
60
    }
61
}
62