forked from mongodb/laravel-mongodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertOneTest.php
61 lines (48 loc) · 1.51 KB
/
InsertOneTest.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
<?php
declare(strict_types=1);
namespace App\Http\Controllers;
use App\Models\Movie;
use Illuminate\Support\Facades\DB;
use MongoDB\Laravel\Tests\TestCase;
class InsertOneTest extends TestCase
{
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testEloquentInsertOne(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
// begin-eloquent-insert-one
$movie = Movie::create([
'title' => 'Marriage Story',
'year' => 2019,
'runtime' => 136,
]);
echo $movie->toJson();
// end-eloquent-insert-one
$this->assertInstanceOf(Movie::class, $movie);
$this->assertSame($movie->title, 'Marriage Story');
$this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","_id":"[a-z0-9]{24}"}$/');
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testQBInsertOne(): void
{
require_once __DIR__ . '/Movie.php';
Movie::truncate();
// begin-qb-insert-one
$success = DB::table('movies')
->insert([
'title' => 'Marriage Story',
'year' => 2019,
'runtime' => 136,
]);
echo 'Insert operation success: ' . ($success ? 'yes' : 'no');
// end-qb-insert-one
$this->expectOutputString('Insert operation success: yes');
}
}