@@ -16,23 +16,10 @@ public function getPackageProviders($app)
1616 return [DatabaseMockServiceProvider::class];
1717 }
1818
19- /**
20- * For testing both Laravel 7.x+ and 6.x-
21- *
22- * @param string $date
23- * @return string
24- */
25- protected function formatDate (string $ date ): string
26- {
27- return version_compare ($ this ->app ->version (), '7 ' , '< ' )
28- ? Carbon::parse ($ date )->format ('Y-m-d H:i:s ' )
29- : $ date ;
30- }
31-
3219 public function testSelectToFetchAll (): void
3320 {
3421 $ pdo = DBMock::mockPdo ();
35- $ pdo ->shouldSelect ('select * from ` users` ' )
22+ $ pdo ->shouldSelect ('select * from " users" ' )
3623 ->shouldFetchAllReturns ([[
3724 'id ' => 1 ,
3825 'name ' => 'John ' ,
@@ -45,8 +32,8 @@ public function testSelectToFetchAll(): void
4532 'id ' => 1 ,
4633 'name ' => 'John ' ,
4734 'email ' => 'john@example.com ' ,
48- 'created_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
49- 'updated_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
35+ 'created_at ' => '2020-01-01T00:00:00.000000Z ' ,
36+ 'updated_at ' => '2020-01-01T00:00:00.000000Z ' ,
5037 ]], User::all ()->toArray ());
5138 }
5239
@@ -56,7 +43,7 @@ public function testInsert(): void
5643
5744 $ pdo = DBMock::mockPdo ();
5845 $ pdo ->shouldInsert (
59- 'insert into ` users` (` name`, ` email`, ` updated_at`, ` created_at` ) values (?, ?, ?, ?) ' ,
46+ 'insert into " users" (" name", " email", " updated_at", " created_at" ) values (?, ?, ?, ?) ' ,
6047 ['John ' , 'john@example.com ' , '2020-01-01 00:00:00 ' , '2020-01-01 00:00:00 ' ]
6148 );
6249 $ pdo ->expects ('lastInsertId ' )->andReturn (2 );
@@ -67,8 +54,8 @@ public function testInsert(): void
6754 'id ' => 2 ,
6855 'name ' => 'John ' ,
6956 'email ' => 'john@example.com ' ,
70- 'created_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
71- 'updated_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
57+ 'created_at ' => '2020-01-01T00:00:00.000000Z ' ,
58+ 'updated_at ' => '2020-01-01T00:00:00.000000Z ' ,
7259 ], $ user ->toArray ());
7360 }
7461
@@ -79,7 +66,7 @@ public function testInsertUsingCallbackMatcher(): void
7966 $ pdo = DBMock::mockPdo ();
8067 $ pdo ->shouldInsert (
8168 Mockery::on (function (string $ sql ) {
82- $ this ->assertSame ('insert into ` users` (` name`, ` email`, ` updated_at`, ` created_at` ) values (?, ?, ?, ?) ' , $ sql );
69+ $ this ->assertSame ('insert into " users" (" name", " email", " updated_at", " created_at" ) values (?, ?, ?, ?) ' , $ sql );
8370 return true ;
8471 }),
8572 ['John ' , 'john@example.com ' , '2020-01-01 00:00:00 ' , '2020-01-01 00:00:00 ' ]
@@ -92,8 +79,8 @@ public function testInsertUsingCallbackMatcher(): void
9279 'id ' => 2 ,
9380 'name ' => 'John ' ,
9481 'email ' => 'john@example.com ' ,
95- 'created_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
96- 'updated_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
82+ 'created_at ' => '2020-01-01T00:00:00.000000Z ' ,
83+ 'updated_at ' => '2020-01-01T00:00:00.000000Z ' ,
9784 ], $ user ->toArray ());
9885 }
9986
@@ -102,7 +89,7 @@ public function testUpdate(): void
10289 Carbon::setTestNow ('2020-01-02 00:00:00 ' );
10390
10491 $ pdo = DBMock::mockPdo ();
105- $ pdo ->shouldSelect ('select * from ` users` where ` email` = ? limit 1 ' , ['john@example.com ' ])
92+ $ pdo ->shouldSelect ('select * from " users" where " email" = ? limit 1 ' , ['john@example.com ' ])
10693 ->shouldFetchAllReturns ([[
10794 'id ' => 2 ,
10895 'name ' => 'John ' ,
@@ -111,9 +98,7 @@ public function testUpdate(): void
11198 'updated_at ' => '2020-01-01 00:00:00 ' ,
11299 ]]);
113100 $ pdo ->shouldUpdateOne (
114- version_compare ($ this ->app ->version (), '5.8 ' , '< ' )
115- ? 'update `users` set `email` = ?, `updated_at` = ? where `id` = ? '
116- : 'update `users` set `email` = ?, `users`.`updated_at` = ? where `id` = ? ' ,
101+ 'update "users" set "email" = ?, "updated_at" = ? where "id" = ? ' ,
117102 ['john-01@example.com ' , '2020-01-02 00:00:00 ' , 2 ]
118103 );
119104
@@ -123,8 +108,8 @@ public function testUpdate(): void
123108 'id ' => 2 ,
124109 'name ' => 'John ' ,
125110 'email ' => 'john-01@example.com ' ,
126- 'created_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
127- 'updated_at ' => $ this -> formatDate ( '2020-01-02T00:00:00.000000Z ' ) ,
111+ 'created_at ' => '2020-01-01T00:00:00.000000Z ' ,
112+ 'updated_at ' => '2020-01-02T00:00:00.000000Z ' ,
128113 ], $ user ->toArray ());
129114 }
130115
@@ -134,7 +119,7 @@ public function testUpdateWithReadReplica(): void
134119
135120 $ pdos = DBMock::mockEachPdo ();
136121 $ pdos ->reader ()
137- ->shouldSelect ('select * from ` users` where ` email` = ? limit 1 ' , ['john@example.com ' ])
122+ ->shouldSelect ('select * from " users" where " email" = ? limit 1 ' , ['john@example.com ' ])
138123 ->shouldFetchAllReturns ([[
139124 'id ' => 2 ,
140125 'name ' => 'John ' ,
@@ -144,9 +129,7 @@ public function testUpdateWithReadReplica(): void
144129 ]]);
145130 $ pdos ->writer ()
146131 ->shouldUpdateOne (
147- version_compare ($ this ->app ->version (), '5.8 ' , '< ' )
148- ? 'update `users` set `email` = ?, `updated_at` = ? where `id` = ? '
149- : 'update `users` set `email` = ?, `users`.`updated_at` = ? where `id` = ? ' ,
132+ 'update "users" set "email" = ?, "updated_at" = ? where "id" = ? ' ,
150133 ['john-01@example.com ' , '2020-01-02 00:00:00 ' , 2 ]
151134 );
152135
@@ -156,8 +139,8 @@ public function testUpdateWithReadReplica(): void
156139 'id ' => 2 ,
157140 'name ' => 'John ' ,
158141 'email ' => 'john-01@example.com ' ,
159- 'created_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
160- 'updated_at ' => $ this -> formatDate ( '2020-01-02T00:00:00.000000Z ' ) ,
142+ 'created_at ' => '2020-01-01T00:00:00.000000Z ' ,
143+ 'updated_at ' => '2020-01-02T00:00:00.000000Z ' ,
161144 ], $ user ->toArray ());
162145 }
163146
@@ -167,12 +150,10 @@ public function testUpdateAndSelectInAnyOrder(): void
167150
168151 $ pdo = DBMock::mockPdo ()->inAnyOrder ();
169152 $ pdo ->shouldUpdateOne (
170- version_compare ($ this ->app ->version (), '5.8 ' , '< ' )
171- ? 'update `users` set `email` = ?, `updated_at` = ? where `id` = ? '
172- : 'update `users` set `email` = ?, `users`.`updated_at` = ? where `id` = ? ' ,
153+ 'update "users" set "email" = ?, "updated_at" = ? where "id" = ? ' ,
173154 ['john-01@example.com ' , '2020-01-02 00:00:00 ' , 2 ]
174155 );
175- $ pdo ->shouldSelect ('select * from ` users` where ` email` = ? limit 1 ' , ['john@example.com ' ])
156+ $ pdo ->shouldSelect ('select * from " users" where " email" = ? limit 1 ' , ['john@example.com ' ])
176157 ->shouldFetchAllReturns ([[
177158 'id ' => 2 ,
178159 'name ' => 'John ' ,
@@ -187,8 +168,8 @@ public function testUpdateAndSelectInAnyOrder(): void
187168 'id ' => 2 ,
188169 'name ' => 'John ' ,
189170 'email ' => 'john-01@example.com ' ,
190- 'created_at ' => $ this -> formatDate ( '2020-01-01T00:00:00.000000Z ' ) ,
191- 'updated_at ' => $ this -> formatDate ( '2020-01-02T00:00:00.000000Z ' ) ,
171+ 'created_at ' => '2020-01-01T00:00:00.000000Z ' ,
172+ 'updated_at ' => '2020-01-02T00:00:00.000000Z ' ,
192173 ], $ user ->toArray ());
193174 }
194175}
0 commit comments