Skip to content

Commit fb48de3

Browse files
committed
Switch models to MongoDB
1 parent e8c06d3 commit fb48de3

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

tests/Eloquent/DatabaseEloquentHasOneOfManyTest.php

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace Eloquent;
44

5-
use Illuminate\Database\Capsule\Manager as DB;
65
use Illuminate\Database\Connection;
7-
use Illuminate\Database\Eloquent\Model as Eloquent;
86
use Illuminate\Database\Eloquent\SoftDeletes;
97
use Illuminate\Database\Schema\Builder;
8+
use MongoDB\Laravel\Eloquent\Model;
109
use MongoDB\Laravel\Tests\TestCase;
1110

1211
use function now;
@@ -22,15 +21,7 @@ class DatabaseEloquentHasOneOfManyTest extends TestCase
2221
{
2322
protected function setUp(): void
2423
{
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();
3425

3526
$this->createSchema();
3627
}
@@ -82,13 +73,13 @@ protected function tearDown(): void
8273

8374
public function testItGuessesRelationName()
8475
{
85-
$user = \Illuminate\Tests\Database\HasOneOfManyTestUser::make();
76+
$user = HasOneOfManyTestUser::make();
8677
$this->assertSame('latest_login', $user->latest_login()->getRelationName());
8778
}
8879

8980
public function testItGuessesRelationNameAndAddsOfManyWhenTableNameIsRelationName()
9081
{
91-
$model = \Illuminate\Tests\Database\HasOneOfManyTestModel::make();
82+
$model = HasOneOfManyTestModel::make();
9283
$this->assertSame('logins_of_many', $model->logins()->getRelationName());
9384
}
9485

@@ -119,7 +110,7 @@ public function testEagerLoadingAppliesConstraintsToInnerJoinSubQuery()
119110

120111
public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalScope()
121112
{
122-
\Illuminate\Tests\Database\HasOneOfManyTestLogin::addGlobalScope('test', function ($query) {
113+
HasOneOfManyTestLogin::addGlobalScope('test', function ($query) {
123114
$query->orderBy('id');
124115
});
125116

@@ -134,7 +125,7 @@ public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalSco
134125

135126
public function testGlobalScopeIsNotAppliedWhenRelationIsDefinedWithoutGlobalScopeWithComplexQuery()
136127
{
137-
\Illuminate\Tests\Database\HasOneOfManyTestPrice::addGlobalScope('test', function ($query) {
128+
HasOneOfManyTestPrice::addGlobalScope('test', function ($query) {
138129
$query->orderBy('id');
139130
});
140131

@@ -524,7 +515,7 @@ public function testItGetsCorrectResultUsingAtLeastTwoAggregatesDistinctFromId()
524515
*/
525516
protected function connection()
526517
{
527-
return Eloquent::getConnectionResolver()->connection();
518+
return Model::getConnectionResolver()->connection('mongodb');
528519
}
529520

530521
/**
@@ -541,8 +532,9 @@ protected function schema()
541532
/**
542533
* Eloquent Models...
543534
*/
544-
class HasOneOfManyTestUser extends Eloquent
535+
class HasOneOfManyTestUser extends Model
545536
{
537+
protected $connection = 'mongodb';
546538
protected $table = 'users';
547539
protected $guarded = [];
548540
public $timestamps = false;
@@ -559,7 +551,7 @@ public function latest_login()
559551

560552
public function latest_login_with_soft_deletes()
561553
{
562-
return $this->hasOne(\Illuminate\Tests\Database\HasOneOfManyTestLoginWithSoftDeletes::class, 'user_id')->ofMany();
554+
return $this->hasOne(HasOneOfManyTestLoginWithSoftDeletes::class, 'user_id')->ofMany();
563555
}
564556

565557
public function latest_login_with_shortcut()
@@ -595,7 +587,7 @@ function ($query) {
595587

596588
public function states()
597589
{
598-
return $this->hasMany(\Illuminate\Tests\Database\HasOneOfManyTestState::class, 'user_id');
590+
return $this->hasMany(HasOneOfManyTestState::class, 'user_id');
599591
}
600592

601593
public function foo_state()
@@ -662,40 +654,44 @@ public function latest_updated_latest_created_state()
662654
}
663655
}
664656

665-
class HasOneOfManyTestModel extends Eloquent
657+
class HasOneOfManyTestModel extends Model
666658
{
667659
public function logins()
668660
{
669661
return $this->hasOne(HasOneOfManyTestLogin::class)->ofMany();
670662
}
671663
}
672664

673-
class HasOneOfManyTestLogin extends Eloquent
665+
class HasOneOfManyTestLogin extends Model
674666
{
667+
protected $connection = 'mongodb';
675668
protected $table = 'logins';
676669
protected $guarded = [];
677670
public $timestamps = false;
678671
}
679672

680-
class HasOneOfManyTestLoginWithSoftDeletes extends Eloquent
673+
class HasOneOfManyTestLoginWithSoftDeletes extends Model
681674
{
682675
use SoftDeletes;
683676

677+
protected $connection = 'mongodb';
684678
protected $table = 'logins';
685679
protected $guarded = [];
686680
public $timestamps = false;
687681
}
688682

689-
class HasOneOfManyTestState extends Eloquent
683+
class HasOneOfManyTestState extends Model
690684
{
685+
protected $connection = 'mongodb';
691686
protected $table = 'states';
692687
protected $guarded = [];
693688
public $timestamps = true;
694689
protected $fillable = ['type', 'state', 'updated_at'];
695690
}
696691

697-
class HasOneOfManyTestPrice extends Eloquent
692+
class HasOneOfManyTestPrice extends Model
698693
{
694+
protected $connection = 'mongodb';
699695
protected $table = 'prices';
700696
protected $guarded = [];
701697
public $timestamps = false;

0 commit comments

Comments
 (0)