FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
framework/tests/Database/DatabaseEloquentPivotTest.php at master · JavaDevl/framework · GitHub
JavaDevl
framework
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
framework
/
tests
/
Database
/
DatabaseEloquentPivotTest.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
121 lines (99 loc) · 4.66 KB
Breadcrumbs
framework
/
tests
/
Database
/
DatabaseEloquentPivotTest.php
Copy path
File metadata and controls
executable file
·
121 lines (99 loc) · 4.66 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
115
116
117
118
119
120
121
<?php
use
Mockery
as
m
;
use
Illuminate
\
Database
\
Eloquent
\
Relations
\
Pivot
;
class
DatabaseEloquentPivotTest
extends
PHPUnit_Framework_TestCase
{
public
function
tearDown
()
{
m::
close
();
}
public
function
testPropertiesAreSetCorrectly
()
{
$
parent
= m::
mock
(
'
Illuminate\Database\Eloquent\Model[getConnectionName]
'
);
$
parent
->
shouldReceive
(
'
getConnectionName
'
)->
once
()->
andReturn
(
'
connection
'
);
$
parent
->
getConnection
()->
getQueryGrammar
()->
shouldReceive
(
'
getDateFormat
'
)->
andReturn
(
'
Y-m-d H:i:s
'
);
$
parent
->
setDateFormat
(
'
Y-m-d H:i:s
'
);
$
pivot
=
new
Pivot
(
$
parent
, [
'
foo
'
=>
'
bar
'
,
'
created_at
'
=>
'
2015-09-12
'
],
'
table
'
,
true
);
$
this
->
assertEquals
([
'
foo
'
=>
'
bar
'
,
'
created_at
'
=>
'
2015-09-12 00:00:00
'
],
$
pivot
->
getAttributes
());
$
this
->
assertEquals
(
'
connection
'
,
$
pivot
->
getConnectionName
());
$
this
->
assertEquals
(
'
table
'
,
$
pivot
->
getTable
());
$
this
->
assertTrue
(
$
pivot
->
exists
);
}
public
function
testMutatorsAreCalledFromConstructor
()
{
$
parent
= m::
mock
(
'
Illuminate\Database\Eloquent\Model[getConnectionName]
'
);
$
parent
->
shouldReceive
(
'
getConnectionName
'
)->
once
()->
andReturn
(
'
connection
'
);
$
pivot
=
new
DatabaseEloquentPivotTestMutatorStub
(
$
parent
, [
'
foo
'
=>
'
bar
'
],
'
table
'
,
true
);
$
this
->
assertTrue
(
$
pivot
->
getMutatorCalled
());
}
public
function
testPropertiesUnchangedAreNotDirty
()
{
$
parent
= m::
mock
(
'
Illuminate\Database\Eloquent\Model[getConnectionName]
'
);
$
parent
->
shouldReceive
(
'
getConnectionName
'
)->
once
()->
andReturn
(
'
connection
'
);
$
pivot
=
new
Pivot
(
$
parent
, [
'
foo
'
=>
'
bar
'
,
'
shimy
'
=>
'
shake
'
],
'
table
'
,
true
);
$
this
->
assertEquals
([],
$
pivot
->
getDirty
());
}
public
function
testPropertiesChangedAreDirty
()
{
$
parent
= m::
mock
(
'
Illuminate\Database\Eloquent\Model[getConnectionName]
'
);
$
parent
->
shouldReceive
(
'
getConnectionName
'
)->
once
()->
andReturn
(
'
connection
'
);
$
pivot
=
new
Pivot
(
$
parent
, [
'
foo
'
=>
'
bar
'
,
'
shimy
'
=>
'
shake
'
],
'
table
'
,
true
);
$
pivot
->
shimy
=
'
changed
'
;
$
this
->
assertEquals
([
'
shimy
'
=>
'
changed
'
],
$
pivot
->
getDirty
());
}
public
function
testTimestampPropertyIsSetIfCreatedAtInAttributes
()
{
$
parent
= m::
mock
(
'
Illuminate\Database\Eloquent\Model[getConnectionName,getDates]
'
);
$
parent
->
shouldReceive
(
'
getConnectionName
'
)->
andReturn
(
'
connection
'
);
$
parent
->
shouldReceive
(
'
getDates
'
)->
andReturn
([]);
$
pivot
=
new
DatabaseEloquentPivotTestDateStub
(
$
parent
, [
'
foo
'
=>
'
bar
'
,
'
created_at
'
=>
'
foo
'
],
'
table
'
);
$
this
->
assertTrue
(
$
pivot
->
timestamps
);
$
pivot
=
new
DatabaseEloquentPivotTestDateStub
(
$
parent
, [
'
foo
'
=>
'
bar
'
],
'
table
'
);
$
this
->
assertFalse
(
$
pivot
->
timestamps
);
}
public
function
testKeysCanBeSetProperly
()
{
$
parent
= m::
mock
(
'
Illuminate\Database\Eloquent\Model[getConnectionName]
'
);
$
parent
->
shouldReceive
(
'
getConnectionName
'
)->
once
()->
andReturn
(
'
connection
'
);
$
pivot
=
new
Pivot
(
$
parent
, [
'
foo
'
=>
'
bar
'
],
'
table
'
);
$
pivot
->
setPivotKeys
(
'
foreign
'
,
'
other
'
);
$
this
->
assertEquals
(
'
foreign
'
,
$
pivot
->
getForeignKey
());
$
this
->
assertEquals
(
'
other
'
,
$
pivot
->
getOtherKey
());
}
public
function
testDeleteMethodDeletesModelByKeys
()
{
$
parent
= m::
mock
(
'
Illuminate\Database\Eloquent\Model[getConnectionName]
'
);
$
parent
->
guard
([]);
$
parent
->
shouldReceive
(
'
getConnectionName
'
)->
once
()->
andReturn
(
'
connection
'
);
$
pivot
=
$
this
->
getMock
(
'
Illuminate\Database\Eloquent\Relations\Pivot
'
, [
'
newQuery
'
], [
$
parent
, [
'
foo
'
=>
'
bar
'
],
'
table
'
]);
$
pivot
->
setPivotKeys
(
'
foreign
'
,
'
other
'
);
$
pivot
->
foreign
=
'
foreign.value
'
;
$
pivot
->
other
=
'
other.value
'
;
$
query
= m::
mock
(
'
stdClass
'
);
$
query
->
shouldReceive
(
'
where
'
)->
once
()->
with
(
'
foreign
'
,
'
foreign.value
'
)->
andReturn
(
$
query
);
$
query
->
shouldReceive
(
'
where
'
)->
once
()->
with
(
'
other
'
,
'
other.value
'
)->
andReturn
(
$
query
);
$
query
->
shouldReceive
(
'
delete
'
)->
once
()->
andReturn
(
true
);
$
pivot
->
expects
(
$
this
->
once
())->
method
(
'
newQuery
'
)->
will
(
$
this
->
returnValue
(
$
query
));
$
this
->
assertTrue
(
$
pivot
->
delete
());
}
}
class
DatabaseEloquentPivotTestDateStub
extends
Illuminate
\
Database
\
Eloquent
\
Relations
\Pivot
{
public
function
getDates
()
{
return
[];
}
}
class
DatabaseEloquentPivotTestMutatorStub
extends
Illuminate
\
Database
\
Eloquent
\
Relations
\Pivot
{
private
$
mutatorCalled
=
false
;
public
function
setFooAttribute
(
$
value
)
{
$
this
->
mutatorCalled
=
true
;
return
$
value
;
}
public
function
getMutatorCalled
()
{
return
$
this
->
mutatorCalled
;
}
}
Back
|
FazBrowse Home
|
New Git URL