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

HasOneTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 0
dl 0
loc 29
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Records\Tests\Relations;
4
5
use Mockery as m;
6
use Nip\Records\Collections\Collection;
7
use Nip\Records\Record;
8
use Nip\Records\RecordManager;
9
use Nip\Records\Relations\HasOne;
10
11
/**
12
 * Class HasOneTest
13
 * @package Nip\Records\Tests\Relations
14
 */
15
class HasOneTest extends \Nip\Records\Tests\AbstractTest
16
{
17
18
    /**
19
     * @var HasOne
20
     */
21
    protected $object;
22
23
    public function testInitResults()
24
    {
25
        static::assertSame($this->_user, $this->object->getResults());
26
    }
27
28
    protected function setUp()
29
    {
30
        parent::setUp();
31
32
        $this->object = new HasOne();
33
        $this->object->setName('User');
34
        $this->object->addParams(['withPK' => 'id_custom']);
35
36
        $this->_user = new Record();
0 ignored issues
show
Bug Best Practice introduced by
The property _user does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
38
        $users = m::namedMock('Users', \Nip\Records\RecordManager::class)->makePartial();
39
        $users->setPrimaryKey('id');
40
41
        $users->shouldReceive('instance')->andReturnSelf();
42
        $users->shouldReceive('findByField')
43
            ->withArgs(['id_user', 3])
44
            ->andReturn(new Collection([$this->_user]));
45
46
        $this->object->setWith($users);
47
48
        $articleManager = new RecordManager();
49
        $articleManager->setPrimaryKey('id');
50
        $articleManager->setPrimaryFK('id_user');
51
52
        $article = new Record();
53
        $article->id = 3;
54
        $article->setManager($articleManager);
55
56
        $this->object->setItem($article);
57
    }
58
}
59