forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateManyTest.php
76 lines (64 loc) · 1.83 KB
/
UpdateManyTest.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
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Support\Facades\DB;
use MongoDB\Laravel\Tests\TestCase;
class UpdateManyTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testUpdateMany(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
Movie::insert([
[
'title' => 'Hollywood',
'imdb' => [
'rating' => 9.1,
'votes' => 511,
],
],
[
'title' => 'The Shawshank Redemption',
'imdb' => [
'rating' => 9.3,
'votes' => 1513145,
],
],
]);
// begin-eloquent-update-many
$updates = Movie::where('imdb.rating', '>', 9.0)
->update(['acclaimed' => true]);
echo 'Updated documents: ' . $updates;
// end-eloquent-update-many
$this->assertEquals(2, $updates);
Movie::insert([
[
'title' => 'ABCD',
'imdb' => [
'rating' => 9.5,
'votes' => 1,
],
],
[
'title' => 'Testing',
'imdb' => [
'rating' => 9.3,
'votes' => 1,
],
],
]);
// begin-qb-update-many
$updates = DB::table('movies')
->where('imdb.rating', '>', 9.0)
->update(['acclaimed' => true]);
echo 'Updated documents: ' . $updates;
// end-qb-update-many
$this->assertEquals(2, $updates);
$this->expectOutputString('Updated documents: 2Updated documents: 2');
}
}