5
5
namespace App \Http \Controllers ;
6
6
7
7
use App \Models \Movie ;
8
+ use Illuminate \Support \Facades \DB ;
8
9
use MongoDB \Laravel \Tests \TestCase ;
9
10
10
11
class FindOneTest extends TestCase
@@ -13,7 +14,7 @@ class FindOneTest extends TestCase
13
14
* @runInSeparateProcess
14
15
* @preserveGlobalState disabled
15
16
*/
16
- public function testFindOne (): void
17
+ public function testEloquentFindOne (): void
17
18
{
18
19
require_once __DIR__ . '/Movie.php ' ;
19
20
@@ -22,15 +23,41 @@ public function testFindOne(): void
22
23
['title ' => 'The Shawshank Redemption ' , 'directors ' => ['Frank Darabont ' , 'Rob Reiner ' ]],
23
24
]);
24
25
25
- // begin-find-one
26
+ // begin-eloquent- find-one
26
27
$ movie = Movie::where ('directors ' , 'Rob Reiner ' )
27
- ->orderBy ('_id ' )
28
+ ->orderBy ('id ' )
28
29
->first ();
29
30
30
31
echo $ movie ->toJson ();
31
- // end-find-one
32
+ // end-eloquent- find-one
32
33
33
34
$ this ->assertInstanceOf (Movie::class, $ movie );
34
35
$ this ->expectOutputRegex ('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/ ' );
35
36
}
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
+ }
36
63
}
0 commit comments