-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Copy pathFindOneTest.php
63 lines (50 loc) · 1.62 KB
/
FindOneTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Support\Facades\DB;
use MongoDB\Laravel\Tests\TestCase;
class FindOneTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testEloquentFindOne(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
Movie::insert([
['title' => 'The Shawshank Redemption', 'directors' => ['Frank Darabont', 'Rob Reiner']],
]);
// begin-eloquent-find-one
$movie = Movie::where('directors', 'Rob Reiner')
->orderBy('id')
->first();
echo $movie->toJson();
// end-eloquent-find-one
$this->assertInstanceOf(Movie::class, $movie);
$this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/');
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testQBFindOne(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
Movie::insert([
['title' => 'The Shawshank Redemption', 'directors' => ['Frank Darabont', 'Rob Reiner']],
]);
// begin-qb-find-one
$movie = DB::table('movies')
->where('directors', 'Rob Reiner')
->orderBy('_id')
->first();
echo $movie->title;
// end-qb-find-one
$this->assertSame($movie->title, 'The Shawshank Redemption');
$this->expectOutputString('The Shawshank Redemption');
}
}