4
4
5
5
namespace MongoDB \Laravel \Tests ;
6
6
7
- use Illuminate \Database \MySqlConnection ;
7
+ use Illuminate \Database \SQLiteConnection ;
8
8
use Illuminate \Support \Facades \DB ;
9
9
use MongoDB \Laravel \Tests \Models \Book ;
10
- use MongoDB \Laravel \Tests \Models \MysqlBook ;
11
- use MongoDB \Laravel \Tests \Models \MysqlRole ;
12
- use MongoDB \Laravel \Tests \Models \MysqlUser ;
13
10
use MongoDB \Laravel \Tests \Models \Role ;
11
+ use MongoDB \Laravel \Tests \Models \SqlBook ;
12
+ use MongoDB \Laravel \Tests \Models \SqlRole ;
13
+ use MongoDB \Laravel \Tests \Models \SqlUser ;
14
14
use MongoDB \Laravel \Tests \Models \User ;
15
15
use PDOException ;
16
16
@@ -21,90 +21,90 @@ public function setUp(): void
21
21
parent ::setUp ();
22
22
23
23
try {
24
- DB ::connection ('mysql ' )->select ('SELECT 1 ' );
24
+ DB ::connection ('sqlite ' )->select ('SELECT 1 ' );
25
25
} catch (PDOException ) {
26
- $ this ->markTestSkipped ('MySQL connection is not available. ' );
26
+ $ this ->markTestSkipped ('SQLite connection is not available. ' );
27
27
}
28
28
29
- MysqlUser ::executeSchema ();
30
- MysqlBook ::executeSchema ();
31
- MysqlRole ::executeSchema ();
29
+ SqlUser ::executeSchema ();
30
+ SqlBook ::executeSchema ();
31
+ SqlRole ::executeSchema ();
32
32
}
33
33
34
34
public function tearDown (): void
35
35
{
36
- MysqlUser ::truncate ();
37
- MysqlBook ::truncate ();
38
- MysqlRole ::truncate ();
36
+ SqlUser ::truncate ();
37
+ SqlBook ::truncate ();
38
+ SqlRole ::truncate ();
39
39
}
40
40
41
- public function testMysqlRelations ()
41
+ public function testSqlRelations ()
42
42
{
43
- $ user = new MysqlUser ();
44
- $ this ->assertInstanceOf (MysqlUser ::class, $ user );
45
- $ this ->assertInstanceOf (MySqlConnection ::class, $ user ->getConnection ());
43
+ $ user = new SqlUser ();
44
+ $ this ->assertInstanceOf (SqlUser ::class, $ user );
45
+ $ this ->assertInstanceOf (SQLiteConnection ::class, $ user ->getConnection ());
46
46
47
- // Mysql User
47
+ // SQL User
48
48
$ user ->name = 'John Doe ' ;
49
49
$ user ->save ();
50
50
$ this ->assertIsInt ($ user ->id );
51
51
52
52
// SQL has many
53
53
$ book = new Book (['title ' => 'Game of Thrones ' ]);
54
54
$ user ->books ()->save ($ book );
55
- $ user = MysqlUser ::find ($ user ->id ); // refetch
55
+ $ user = SqlUser ::find ($ user ->id ); // refetch
56
56
$ this ->assertCount (1 , $ user ->books );
57
57
58
58
// MongoDB belongs to
59
59
$ book = $ user ->books ()->first (); // refetch
60
- $ this ->assertEquals ('John Doe ' , $ book ->mysqlAuthor ->name );
60
+ $ this ->assertEquals ('John Doe ' , $ book ->sqlAuthor ->name );
61
61
62
62
// SQL has one
63
63
$ role = new Role (['type ' => 'admin ' ]);
64
64
$ user ->role ()->save ($ role );
65
- $ user = MysqlUser ::find ($ user ->id ); // refetch
65
+ $ user = SqlUser ::find ($ user ->id ); // refetch
66
66
$ this ->assertEquals ('admin ' , $ user ->role ->type );
67
67
68
68
// MongoDB belongs to
69
69
$ role = $ user ->role ()->first (); // refetch
70
- $ this ->assertEquals ('John Doe ' , $ role ->mysqlUser ->name );
70
+ $ this ->assertEquals ('John Doe ' , $ role ->sqlUser ->name );
71
71
72
72
// MongoDB User
73
73
$ user = new User ();
74
74
$ user ->name = 'John Doe ' ;
75
75
$ user ->save ();
76
76
77
77
// MongoDB has many
78
- $ book = new MysqlBook (['title ' => 'Game of Thrones ' ]);
79
- $ user ->mysqlBooks ()->save ($ book );
78
+ $ book = new SqlBook (['title ' => 'Game of Thrones ' ]);
79
+ $ user ->sqlBooks ()->save ($ book );
80
80
$ user = User::find ($ user ->_id ); // refetch
81
- $ this ->assertCount (1 , $ user ->mysqlBooks );
81
+ $ this ->assertCount (1 , $ user ->sqlBooks );
82
82
83
83
// SQL belongs to
84
- $ book = $ user ->mysqlBooks ()->first (); // refetch
84
+ $ book = $ user ->sqlBooks ()->first (); // refetch
85
85
$ this ->assertEquals ('John Doe ' , $ book ->author ->name );
86
86
87
87
// MongoDB has one
88
- $ role = new MysqlRole (['type ' => 'admin ' ]);
89
- $ user ->mysqlRole ()->save ($ role );
88
+ $ role = new SqlRole (['type ' => 'admin ' ]);
89
+ $ user ->sqlRole ()->save ($ role );
90
90
$ user = User::find ($ user ->_id ); // refetch
91
- $ this ->assertEquals ('admin ' , $ user ->mysqlRole ->type );
91
+ $ this ->assertEquals ('admin ' , $ user ->sqlRole ->type );
92
92
93
93
// SQL belongs to
94
- $ role = $ user ->mysqlRole ()->first (); // refetch
94
+ $ role = $ user ->sqlRole ()->first (); // refetch
95
95
$ this ->assertEquals ('John Doe ' , $ role ->user ->name );
96
96
}
97
97
98
98
public function testHybridWhereHas ()
99
99
{
100
- $ user = new MysqlUser ();
101
- $ otherUser = new MysqlUser ();
102
- $ this ->assertInstanceOf (MysqlUser ::class, $ user );
103
- $ this ->assertInstanceOf (MySqlConnection ::class, $ user ->getConnection ());
104
- $ this ->assertInstanceOf (MysqlUser ::class, $ otherUser );
105
- $ this ->assertInstanceOf (MySqlConnection ::class, $ otherUser ->getConnection ());
106
-
107
- //MySql User
100
+ $ user = new SqlUser ();
101
+ $ otherUser = new SqlUser ();
102
+ $ this ->assertInstanceOf (SqlUser ::class, $ user );
103
+ $ this ->assertInstanceOf (SQLiteConnection ::class, $ user ->getConnection ());
104
+ $ this ->assertInstanceOf (SqlUser ::class, $ otherUser );
105
+ $ this ->assertInstanceOf (SQLiteConnection ::class, $ otherUser ->getConnection ());
106
+
107
+ // SQL User
108
108
$ user ->name = 'John Doe ' ;
109
109
$ user ->id = 2 ;
110
110
$ user ->save ();
@@ -130,19 +130,19 @@ public function testHybridWhereHas()
130
130
new Book (['title ' => 'Harry Planter ' ]),
131
131
]);
132
132
133
- $ users = MysqlUser ::whereHas ('books ' , function ($ query ) {
133
+ $ users = SqlUser ::whereHas ('books ' , function ($ query ) {
134
134
return $ query ->where ('title ' , 'LIKE ' , 'Har% ' );
135
135
})->get ();
136
136
137
137
$ this ->assertEquals (2 , $ users ->count ());
138
138
139
- $ users = MysqlUser ::whereHas ('books ' , function ($ query ) {
139
+ $ users = SqlUser ::whereHas ('books ' , function ($ query ) {
140
140
return $ query ->where ('title ' , 'LIKE ' , 'Harry% ' );
141
141
}, '>= ' , 2 )->get ();
142
142
143
143
$ this ->assertEquals (1 , $ users ->count ());
144
144
145
- $ books = Book::whereHas ('mysqlAuthor ' , function ($ query ) {
145
+ $ books = Book::whereHas ('sqlAuthor ' , function ($ query ) {
146
146
return $ query ->where ('name ' , 'LIKE ' , 'Other% ' );
147
147
})->get ();
148
148
@@ -151,14 +151,14 @@ public function testHybridWhereHas()
151
151
152
152
public function testHybridWith ()
153
153
{
154
- $ user = new MysqlUser ();
155
- $ otherUser = new MysqlUser ();
156
- $ this ->assertInstanceOf (MysqlUser ::class, $ user );
157
- $ this ->assertInstanceOf (MySqlConnection ::class, $ user ->getConnection ());
158
- $ this ->assertInstanceOf (MysqlUser ::class, $ otherUser );
159
- $ this ->assertInstanceOf (MySqlConnection ::class, $ otherUser ->getConnection ());
160
-
161
- //MySql User
154
+ $ user = new SqlUser ();
155
+ $ otherUser = new SqlUser ();
156
+ $ this ->assertInstanceOf (SqlUser ::class, $ user );
157
+ $ this ->assertInstanceOf (SQLiteConnection ::class, $ user ->getConnection ());
158
+ $ this ->assertInstanceOf (SqlUser ::class, $ otherUser );
159
+ $ this ->assertInstanceOf (SQLiteConnection ::class, $ otherUser ->getConnection ());
160
+
161
+ // SQL User
162
162
$ user ->name = 'John Doe ' ;
163
163
$ user ->id = 2 ;
164
164
$ user ->save ();
@@ -171,18 +171,18 @@ public function testHybridWith()
171
171
$ this ->assertIsInt ($ otherUser ->id );
172
172
// Clear to start
173
173
Book::truncate ();
174
- MysqlBook ::truncate ();
174
+ SqlBook ::truncate ();
175
175
// Create books
176
- // Mysql relation
177
- $ user ->mysqlBooks ()->saveMany ([
178
- new MysqlBook (['title ' => 'Game of Thrones ' ]),
179
- new MysqlBook (['title ' => 'Harry Potter ' ]),
176
+ // SQL relation
177
+ $ user ->sqlBooks ()->saveMany ([
178
+ new SqlBook (['title ' => 'Game of Thrones ' ]),
179
+ new SqlBook (['title ' => 'Harry Potter ' ]),
180
180
]);
181
181
182
- $ otherUser ->mysqlBooks ()->saveMany ([
183
- new MysqlBook (['title ' => 'Harry Plants ' ]),
184
- new MysqlBook (['title ' => 'Harveys ' ]),
185
- new MysqlBook (['title ' => 'Harry Planter ' ]),
182
+ $ otherUser ->sqlBooks ()->saveMany ([
183
+ new SqlBook (['title ' => 'Harry Plants ' ]),
184
+ new SqlBook (['title ' => 'Harveys ' ]),
185
+ new SqlBook (['title ' => 'Harry Planter ' ]),
186
186
]);
187
187
// SQL has many Hybrid
188
188
$ user ->books ()->saveMany ([
@@ -196,12 +196,12 @@ public function testHybridWith()
196
196
new Book (['title ' => 'Harry Planter ' ]),
197
197
]);
198
198
199
- MysqlUser ::with ('books ' )->get ()
199
+ SqlUser ::with ('books ' )->get ()
200
200
->each (function ($ user ) {
201
201
$ this ->assertEquals ($ user ->id , $ user ->books ->count ());
202
202
});
203
203
204
- MysqlUser ::whereHas ('mysqlBooks ' , function ($ query ) {
204
+ SqlUser ::whereHas ('sqlBooks ' , function ($ query ) {
205
205
return $ query ->where ('title ' , 'LIKE ' , 'Harry% ' );
206
206
})
207
207
->with ('books ' )
0 commit comments