forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertManyTest.php
69 lines (58 loc) · 2.02 KB
/
InsertManyTest.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
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Movie;
use DateTimeImmutable;
use Illuminate\Support\Facades\DB;
use MongoDB\BSON\UTCDateTime;
use MongoDB\Laravel\Tests\TestCase;
class InsertManyTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testInsertMany(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
// begin-eloquent-insert-many
$success = Movie::insert([
[
'title' => 'Anatomy of a Fall',
'release_date' => new UTCDateTime(new DateTimeImmutable('2023-08-23')),
],
[
'title' => 'The Boy and the Heron',
'release_date' => new UTCDateTime(new DateTimeImmutable('2023-12-08')),
],
[
'title' => 'Passages',
'release_date' => new UTCDateTime(new DateTimeImmutable('2023-06-28')),
],
]);
echo 'Insert operation success: ' . ($success ? 'yes' : 'no');
// end-eloquent-insert-many
$this->assertTrue($success);
// begin-qb-insert-many
$success = DB::table('movies')
->insert([
[
'title' => 'Anatomy of a Fall',
'release_date' => new UTCDateTime(new DateTimeImmutable('2023-08-23')),
],
[
'title' => 'The Boy and the Heron',
'release_date' => new UTCDateTime(new DateTimeImmutable('2023-12-08')),
],
[
'title' => 'Passages',
'release_date' => new UTCDateTime(new DateTimeImmutable('2023-06-28')),
],
]);
echo 'Insert operation success: ' . ($success ? 'yes' : 'no');
// end-qb-insert-many
$this->assertTrue($success);
$this->expectOutputString('Insert operation success: yesInsert operation success: yes');
}
}