55namespace App \Http \Controllers ;
66
77use App \Models \Movie ;
8+ use Illuminate \Support \Facades \DB ;
89use MongoDB \Laravel \Tests \TestCase ;
910
1011class FindOneTest extends TestCase
@@ -13,7 +14,7 @@ class FindOneTest extends TestCase
1314 * @runInSeparateProcess
1415 * @preserveGlobalState disabled
1516 */
16- public function testFindOne (): void
17+ public function testEloquentFindOne (): void
1718 {
1819 require_once __DIR__ . '/Movie.php ' ;
1920
@@ -22,15 +23,41 @@ public function testFindOne(): void
2223 ['title ' => 'The Shawshank Redemption ' , 'directors ' => ['Frank Darabont ' , 'Rob Reiner ' ]],
2324 ]);
2425
25- // begin-find-one
26+ // begin-eloquent- find-one
2627 $ movie = Movie::where ('directors ' , 'Rob Reiner ' )
27- ->orderBy ('_id ' )
28+ ->orderBy ('id ' )
2829 ->first ();
2930
3031 echo $ movie ->toJson ();
31- // end-find-one
32+ // end-eloquent- find-one
3233
3334 $ this ->assertInstanceOf (Movie::class, $ movie );
3435 $ this ->expectOutputRegex ('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/ ' );
3536 }
37+ 38+ /**
39+ * @runInSeparateProcess
40+ * @preserveGlobalState disabled
41+ */
42+ public function testQBFindOne (): void
43+ {
44+ require_once __DIR__ . '/Movie.php ' ;
45+ 46+ Movie::truncate ();
47+ Movie::insert ([
48+ ['title ' => 'The Shawshank Redemption ' , 'directors ' => ['Frank Darabont ' , 'Rob Reiner ' ]],
49+ ]);
50+ 51+ // begin-qb-find-one
52+ $ movie = DB ::table ('movies ' )
53+ ->where ('directors ' , 'Rob Reiner ' )
54+ ->orderBy ('_id ' )
55+ ->first ();
56+ 57+ echo $ movie ['title ' ];
58+ // end-qb-find-one
59+ 60+ $ this ->assertSame ($ movie ['title ' ], 'The Shawshank Redemption ' );
61+ $ this ->expectOutputString ('The Shawshank Redemption ' );
62+ }
3663}
0 commit comments