forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCountTest.php
53 lines (42 loc) · 1.24 KB
/
CountTest.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
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Support\Facades\DB;
use MongoDB\Laravel\Tests\TestCase;
class CountTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testCount(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
Movie::insert([
[
'title' => 'Young Mr. Lincoln',
'genres' => ['Biography', 'Drama'],
],
[
'title' => 'Million Dollar Mermaid',
'genres' => ['Biography', 'Drama', 'Musical'],
],
]);
// begin-eloquent-count
$count = Movie::where('genres', 'Biography')
->count();
echo 'Number of documents: ' . $count;
// end-eloquent-count
$this->assertEquals(2, $count);
// begin-qb-count
$count = DB::table('movies')
->where('genres', 'Biography')
->count();
echo 'Number of documents: ' . $count;
// end-qb-count
$this->assertEquals(2, $count);
$this->expectOutputString('Number of documents: 2Number of documents: 2');
}
}