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() |
|
|
|
|
52
|
|
|
->shouldReceive('instance')->andReturnSelf() |
53
|
|
|
->shouldReceive('findOne')->andReturn($page) |
|
|
|
|
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
|
|
|
|
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.