Completed
Push — master ( 8d9a79...543cc3 )
by Gabriel
03:32
created

RecordsTest::dataRelationClasses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Records\Tests\Traits\Relations;
4
5
use Mockery as m;
6
use Nip\Database\Connections\Connection;
7
use Nip\Records\RecordManager as Records;
8
use Nip\Records\Relations\BelongsTo;
9
use Nip\Records\Relations\HasAndBelongsToMany;
10
use Nip\Records\Relations\HasMany;
11
use Nip\Records\Relations\HasOne;
12
use Nip\Records\Traits\Relations\HasRelationsRecordsTrait;
13
use Nip\Request;
14
use Nip\Records\Tests\AbstractTest;
15
16
/**
17
 * Class RecordsTest
18
 * @package Nip\Records\Tests
19
 *
20
 * @property HasRelationsRecordsTrait $object
21
 */
22
class RecordsTest extends AbstractTest
23
{
24
    /**
25
     * @dataProvider dataRelationClasses
26
     * @param $class
27
     * @param $name
28
     */
29
    public function testGetRelationClass($class, $name)
30
    {
31
        self::assertEquals($class, $this->object->getRelationClass($name));
32
    }
33
34
    /**
35
     * @dataProvider dataRelationClasses
36
     * @param $class
37
     * @param $name
38
     */
39
    public function testNewRelation($class, $name)
40
    {
41
        self::assertInstanceOf($class, $this->object->newRelation($name));
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function dataRelationClasses()
48
    {
49
        return [
50
            [BelongsTo::class, 'BelongsTo'],
51
            [BelongsTo::class, 'belongsTo'],
52
            [HasOne::class, 'HasOne'],
53
            [HasOne::class, 'hasOne'],
54
            [HasMany::class, 'HasMany'],
55
            [HasMany::class, 'hasMany'],
56
            [HasAndBelongsToMany::class, 'HasAndBelongsToMany'],
57
            [HasAndBelongsToMany::class, 'hasAndBelongsToMany'],
58
        ];
59
    }
60
61
    protected function _testInitRelationsFromArrayBelongsToUser($name)
62
    {
63
        self::assertTrue($this->object->hasRelation($name));
64
        self::assertInstanceOf(BelongsTo::class, $this->object->getRelation($name));
65
        self::assertInstanceOf(Records::class, $this->object->getRelation($name)->getWith());
66
67
        self::assertEquals(
68
            $this->object->getRelation($name)->getWith()->getPrimaryFK(),
69
            $this->object->getRelation($name)->getFK()
70
        );
71
    }
72
73
    protected function setUp()
74
    {
75
        parent::setUp();
76
77
        $wrapper = new Connection(null);
78
79
        $this->object = m::mock(Records::class)->shouldDeferMissing()
0 ignored issues
show
Deprecated Code introduced by
The function Mockery\MockInterface::shouldDeferMissing() has been deprecated: 2.0.0 Please use makePartial() instead ( Ignorable by Annotation )

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

79
        $this->object = /** @scrutinizer ignore-deprecated */ m::mock(Records::class)->shouldDeferMissing()

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Documentation Bug introduced by
It seems like Mockery::mock(Nip\Record...create('/'))->getMock() of type Mockery\MockInterface is incompatible with the declared type Nip\Records\Traits\Relat...asRelationsRecordsTrait of property $object.

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...
80
            ->shouldReceive('getRequest')->andReturn(Request::create('/'))
81
            ->getMock();
82
83
        $this->object->setDB($wrapper);
84
        $this->object->setTable('pages');
85
    }
86
}
87