forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeleteManyTest.php
64 lines (52 loc) · 1.48 KB
/
DeleteManyTest.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
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Support\Facades\DB;
use MongoDB\Laravel\Tests\TestCase;
class DeleteManyTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testDeleteMany(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
Movie::insert([
[
'title' => 'Train Pulling into a Station',
'year' => 1896,
],
[
'title' => 'The Ball Game',
'year' => 1898,
],
]);
// begin-eloquent-delete-many
$deleted = Movie::where('year', '<=', 1910)
->delete();
echo 'Deleted documents: ' . $deleted;
// end-eloquent-delete-many
$this->assertEquals(2, $deleted);
Movie::insert([
[
'title' => 'Train Pulling into a Station',
'year' => 1896,
],
[
'title' => 'The Ball Game',
'year' => 1898,
],
]);
// begin-qb-delete-many
$deleted = DB::table('movies')
->where('year', '<=', 1910)
->delete();
echo 'Deleted documents: ' . $deleted;
// end-qb-delete-many
$this->assertEquals(2, $deleted);
$this->expectOutputString('Deleted documents: 2Deleted documents: 2');
}
}