2
2
3
3
namespace Eloquent ;
4
4
5
- use Illuminate \Database \Capsule \Manager as DB ;
6
5
use Illuminate \Database \Connection ;
7
- use Illuminate \Database \Eloquent \Model as Eloquent ;
8
6
use Illuminate \Database \Eloquent \SoftDeletes ;
9
7
use Illuminate \Database \Schema \Builder ;
8
+ use MongoDB \Laravel \Eloquent \Model ;
10
9
use MongoDB \Laravel \Tests \TestCase ;
11
10
12
11
use function now ;
@@ -22,15 +21,7 @@ class DatabaseEloquentHasOneOfManyTest extends TestCase
22
21
{
23
22
protected function setUp (): void
24
23
{
25
- $ db = new DB ();
26
-
27
- $ db ->addConnection ([
28
- 'driver ' => 'sqlite ' ,
29
- 'database ' => ':memory: ' ,
30
- ]);
31
-
32
- $ db ->bootEloquent ();
33
- $ db ->setAsGlobal ();
24
+ parent ::setUp ();
34
25
35
26
$ this ->createSchema ();
36
27
}
@@ -82,13 +73,13 @@ protected function tearDown(): void
82
73
83
74
public function testItGuessesRelationName ()
84
75
{
85
- $ user = \ Illuminate \ Tests \ Database \ HasOneOfManyTestUser::make ();
76
+ $ user = HasOneOfManyTestUser::make ();
86
77
$ this ->assertSame ('latest_login ' , $ user ->latest_login ()->getRelationName ());
87
78
}
88
79
89
80
public function testItGuessesRelationNameAndAddsOfManyWhenTableNameIsRelationName ()
90
81
{
91
- $ model = \ Illuminate \ Tests \ Database \ HasOneOfManyTestModel::make ();
82
+ $ model = HasOneOfManyTestModel::make ();
92
83
$ this ->assertSame ('logins_of_many ' , $ model ->logins ()->getRelationName ());
93
84
}
94
85
@@ -119,7 +110,7 @@ public function testEagerLoadingAppliesConstraintsToInnerJoinSubQuery()
119
110
120
111
public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalScope ()
121
112
{
122
- \ Illuminate \ Tests \ Database \ HasOneOfManyTestLogin::addGlobalScope ('test ' , function ($ query ) {
113
+ HasOneOfManyTestLogin::addGlobalScope ('test ' , function ($ query ) {
123
114
$ query ->orderBy ('id ' );
124
115
});
125
116
@@ -134,7 +125,7 @@ public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalSco
134
125
135
126
public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalScopeWithComplexQuery ()
136
127
{
137
- \ Illuminate \ Tests \ Database \ HasOneOfManyTestPrice::addGlobalScope ('test ' , function ($ query ) {
128
+ HasOneOfManyTestPrice::addGlobalScope ('test ' , function ($ query ) {
138
129
$ query ->orderBy ('id ' );
139
130
});
140
131
@@ -524,7 +515,7 @@ public function testItGetsCorrectResultUsingAtLeastTwoAggregatesDistinctFromId()
524
515
*/
525
516
protected function connection ()
526
517
{
527
- return Eloquent ::getConnectionResolver ()->connection ();
518
+ return Model ::getConnectionResolver ()->connection (' mongodb ' );
528
519
}
529
520
530
521
/**
@@ -541,8 +532,9 @@ protected function schema()
541
532
/**
542
533
* Eloquent Models...
543
534
*/
544
- class HasOneOfManyTestUser extends Eloquent
535
+ class HasOneOfManyTestUser extends Model
545
536
{
537
+ protected $ connection = 'mongodb ' ;
546
538
protected $ table = 'users ' ;
547
539
protected $ guarded = [];
548
540
public $ timestamps = false ;
@@ -559,7 +551,7 @@ public function latest_login()
559
551
560
552
public function latest_login_with_soft_deletes ()
561
553
{
562
- return $ this ->hasOne (\ Illuminate \ Tests \ Database \ HasOneOfManyTestLoginWithSoftDeletes::class, 'user_id ' )->ofMany ();
554
+ return $ this ->hasOne (HasOneOfManyTestLoginWithSoftDeletes::class, 'user_id ' )->ofMany ();
563
555
}
564
556
565
557
public function latest_login_with_shortcut ()
@@ -595,7 +587,7 @@ function ($query) {
595
587
596
588
public function states ()
597
589
{
598
- return $ this ->hasMany (\ Illuminate \ Tests \ Database \ HasOneOfManyTestState::class, 'user_id ' );
590
+ return $ this ->hasMany (HasOneOfManyTestState::class, 'user_id ' );
599
591
}
600
592
601
593
public function foo_state ()
@@ -662,40 +654,44 @@ public function latest_updated_latest_created_state()
662
654
}
663
655
}
664
656
665
- class HasOneOfManyTestModel extends Eloquent
657
+ class HasOneOfManyTestModel extends Model
666
658
{
667
659
public function logins ()
668
660
{
669
661
return $ this ->hasOne (HasOneOfManyTestLogin::class)->ofMany ();
670
662
}
671
663
}
672
664
673
- class HasOneOfManyTestLogin extends Eloquent
665
+ class HasOneOfManyTestLogin extends Model
674
666
{
667
+ protected $ connection = 'mongodb ' ;
675
668
protected $ table = 'logins ' ;
676
669
protected $ guarded = [];
677
670
public $ timestamps = false ;
678
671
}
679
672
680
- class HasOneOfManyTestLoginWithSoftDeletes extends Eloquent
673
+ class HasOneOfManyTestLoginWithSoftDeletes extends Model
681
674
{
682
675
use SoftDeletes;
683
676
677
+ protected $ connection = 'mongodb ' ;
684
678
protected $ table = 'logins ' ;
685
679
protected $ guarded = [];
686
680
public $ timestamps = false ;
687
681
}
688
682
689
- class HasOneOfManyTestState extends Eloquent
683
+ class HasOneOfManyTestState extends Model
690
684
{
685
+ protected $ connection = 'mongodb ' ;
691
686
protected $ table = 'states ' ;
692
687
protected $ guarded = [];
693
688
public $ timestamps = true ;
694
689
protected $ fillable = ['type ' , 'state ' , 'updated_at ' ];
695
690
}
696
691
697
- class HasOneOfManyTestPrice extends Eloquent
692
+ class HasOneOfManyTestPrice extends Model
698
693
{
694
+ protected $ connection = 'mongodb ' ;
699
695
protected $ table = 'prices ' ;
700
696
protected $ guarded = [];
701
697
public $ timestamps = false ;
0 commit comments