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