MorphToManyTest::getPageTestRecord()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Records\Tests\Relations;
4
5
use Mockery as m;
6
use Nip\Container\Container;
7
use Nip\Database\Connections\Connection;
8
use Nip\Records\Record;
9
use Nip\Records\RecordManager;
10
use Nip\Records\Relations\MorphToMany;
11
12
/**
13
 * Class MorphToManyTest
14
 * @package Nip\Records\Tests\Relations
15
 */
16
class MorphToManyTest extends \Nip\Records\Tests\AbstractTest
17
{
18
    public function testNewQuery()
19
    {
20
        $tagsManager = new RecordManager();
21
        $tagsManager->setTable('tags');
22
23
        $tag = new Record();
24
        $tag->id = 3;
25
26
        $page = $this->getPageTestRecord();
27
28
        $relation = new MorphToMany();
29
        $relation->setItem($tag);
30
        $relation->setManager($tagsManager);
31
        $relation->setWith($page->getManager());
32
        $relation->setJoinFields(['test']);
33
34
        static::assertSame(
35
            "SELECT `pages`.`id` AS `id`, `pages`.`id_page` AS `id_page`, `pages_pivot`.`test` AS `__test` "
36
            . "FROM `pages`, ``.`pages_pivot` "
37
            . "WHERE `pages_pivot`.`id_page` = `pages`.`id` AND `pages_pivot`.`pivotal_type` = 'tags'",
38
            $relation->newQuery()->getString()
39
        );
40
    }
41
42
    /**
43
     * @return Record
44
     */
45
    protected function getPageTestRecord()
46
    {
47
        $page = new Record();
48
        $page->id = 1;
49
50
        /** @var RecordManager $pages */
51
        $pages = m::namedMock('Pages', RecordManager::class)->shouldDeferMissing()
0 ignored issues
show
Deprecated Code introduced by
The function Mockery\LegacyMockInterface::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

51
        $pages = /** @scrutinizer ignore-deprecated */ m::namedMock('Pages', RecordManager::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...
52
            ->shouldReceive('instance')->andReturnSelf()
53
            ->shouldReceive('findOne')->andReturn($page)
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not exist on Mockery\Expectation. ( Ignorable by Annotation )

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

53
            ->/** @scrutinizer ignore-call */ shouldReceive('findOne')->andReturn($page)

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
            ->shouldReceive('getFields')->andReturn(['id','id_page'])
55
            ->getMock();
56
        $pages->setPrimaryKey('id');
57
        $pages->setPrimaryFK('id_page');
58
59
        $page->setManager($pages);
60
        return $page;
61
    }
62
}
63