-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathGH3326Test.php
More file actions
42 lines (34 loc) · 968 Bytes
/
GH3326Test.php
File metadata and controls
42 lines (34 loc) · 968 Bytes
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
<?php
declare(strict_types=1);
namespace MongoDB\Laravel\Tests\Ticket;
use MongoDB\Laravel\Eloquent\Model;
use MongoDB\Laravel\Tests\TestCase;
/**
* @see https://github.com/mongodb/laravel-mongodb/issues/3326
* @see https://jira.mongodb.org/browse/PHPORM-309
*/
class GH3326Test extends TestCase
{
public function testCreatedEventCanSafelyCallSave(): void
{
$model = new GH3326Model();
$model->foo = 'bar';
$model->save();
$fresh = $model->fresh();
$this->assertEquals('bar', $fresh->foo);
$this->assertEquals('written-in-created', $fresh->extra);
}
}
class GH3326Model extends Model
{
protected $connection = 'mongodb';
protected $collection = 'test_gh3326';
protected $guarded = [];
protected static function booted(): void
{
static::created(function ($model) {
$model->extra = 'written-in-created';
$model->saveQuietly();
});
}
}