FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
framework/tests/Database/DatabaseEloquentRelationTest.php at master · JavaDevl/framework · GitHub
JavaDevl
/
framework
Public
forked from
laravel/framework
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
framework
/
tests
/
Database
/
DatabaseEloquentRelationTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
114 lines (95 loc) · 3.62 KB
Breadcrumbs
framework
/
tests
/
Database
/
DatabaseEloquentRelationTest.php
Copy path
File metadata and controls
executable file
·
114 lines (95 loc) · 3.62 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
use
Mockery
as
m
;
use
Illuminate
\
Database
\
Grammar
;
use
Illuminate
\
Database
\
Eloquent
\
Model
;
use
Illuminate
\
Database
\
Eloquent
\
Builder
;
use
Illuminate
\
Database
\
Eloquent
\
Relations
\
HasOne
;
use
Illuminate
\
Database
\
Eloquent
\
Relations
\
Relation
;
use
Illuminate
\
Database
\
Query
\
Builder
as
QueryBuilder
;
class
DatabaseEloquentRelationTest
extends
PHPUnit_Framework_TestCase
{
public
function
tearDown
()
{
m::
close
();
}
public
function
testSetRelationFail
()
{
$
parent
=
new
EloquentRelationResetModelStub
;
$
relation
=
new
EloquentRelationResetModelStub
;
$
parent
->
setRelation
(
'
test
'
,
$
relation
);
$
parent
->
setRelation
(
'
foo
'
,
'
bar
'
);
$
this
->
assertArrayNotHasKey
(
'
foo
'
,
$
parent
->
toArray
());
}
public
function
testTouchMethodUpdatesRelatedTimestamps
()
{
$
builder
= m::
mock
(Builder::class);
$
parent
= m::
mock
(Model::class);
$
parent
->
shouldReceive
(
'
getAttribute
'
)->
with
(
'
id
'
)->
andReturn
(
1
);
$
builder
->
shouldReceive
(
'
getModel
'
)->
andReturn
(
$
related
= m::
mock
(StdClass::class));
$
builder
->
shouldReceive
(
'
whereNotNull
'
);
$
builder
->
shouldReceive
(
'
where
'
);
$
relation
=
new
HasOne
(
$
builder
,
$
parent
,
'
foreign_key
'
,
'
id
'
);
$
related
->
shouldReceive
(
'
getTable
'
)->
andReturn
(
'
table
'
);
$
related
->
shouldReceive
(
'
getUpdatedAtColumn
'
)->
andReturn
(
'
updated_at
'
);
$
now
=
Carbon
\Carbon::
now
();
$
related
->
shouldReceive
(
'
freshTimestampString
'
)->
andReturn
(
$
now
);
$
builder
->
shouldReceive
(
'
update
'
)->
once
()->
with
([
'
updated_at
'
=>
$
now
]);
$
relation
->
touch
();
}
public
function
testSettingMorphMapWithNumericArrayUsesTheTableNames
()
{
Relation::
morphMap
([EloquentRelationResetModelStub::class]);
$
this
->
assertEquals
([
'
reset
'
=>
'
EloquentRelationResetModelStub
'
,
], Relation::
morphMap
());
Relation::
morphMap
([],
false
);
}
/**
* Testing to ensure loop does not occur during relational queries in global scopes.
*
* Executing parent model's global scopes could result in an infinite loop when the
* parent model's global scope utilizes a relation in a query like has or whereHas
*/
public
function
testDonNotRunParentModelGlobalScopes
()
{
/* @var Mockery\MockInterface $parent */
$
eloquentBuilder
= m::
mock
(Builder::class);
$
queryBuilder
= m::
mock
(QueryBuilder::class);
$
parent
= m::
mock
(EloquentRelationResetModelStub::class)->
makePartial
();
$
grammar
= m::
mock
(Grammar::class);
$
eloquentBuilder
->
shouldReceive
(
'
getModel
'
)->
andReturn
(
$
related
= m::
mock
(StdClass::class));
$
eloquentBuilder
->
shouldReceive
(
'
getQuery
'
)->
andReturn
(
$
queryBuilder
);
$
queryBuilder
->
shouldReceive
(
'
getGrammar
'
)->
andReturn
(
$
grammar
);
$
grammar
->
shouldReceive
(
'
wrap
'
);
$
parent
->
shouldReceive
(
'
newQueryWithoutScopes
'
)->
andReturn
(
$
eloquentBuilder
);
$
relation
=
new
EloquentRelationStub
(
$
eloquentBuilder
,
$
parent
);
$
relation
->
wrap
(
'
test
'
);
}
}
class
EloquentRelationResetModelStub
extends
Model
{
protected
$
table
=
'
reset
'
;
// Override method call which would normally go through __call()
public
function
getQuery
()
{
return
$
this
->
newQuery
()->
getQuery
();
}
}
class
EloquentRelationStub
extends
Relation
{
public
function
addConstraints
()
{
}
public
function
addEagerConstraints
(
array
$
models
)
{
}
public
function
initRelation
(
array
$
models
,
$
relation
)
{
}
public
function
match
(
array
$
models
,
Illuminate
\
Database
\
Eloquent
\
Collection
$
results
,
$
relation
)
{
}
public
function
getResults
()
{
}
}
Back
|
FazBrowse Home
|
New Git URL