Skip to content

Commit 19dbc19

Browse files
committed
refs #2923 Allow mutation elocument model on getContent
1 parent 0b14b8b commit 19dbc19

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Screen/AsSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@ public function getContent(string $field): mixed
3232

3333
return $this->getAttribute($field) // Try to get the field value from the object's attributes.
3434
?? Arr::get($this->getRelations(), $field) // Try to get the field value from the object's relations.
35-
?? Arr::get($this, $field); // Try to get the field value from the object's array representation.
35+
?? Arr::get($this->attributesToArray(), $field); // Try to get the field value from the object's array representation.
3636
}
3737
}

tests/Unit/Screen/SourceTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,20 @@ protected function setUp(): void
2424
{
2525
use AsSource;
2626

27+
protected $attributes = [
28+
'preferences' => '{"theme":"dark","notifications":{"email":true,"sms":false}}',
29+
];
30+
2731
protected $fillable = [
2832
'id',
2933
'name',
3034
'options',
35+
'preferences',
3136
];
3237

3338
protected $casts = [
34-
'options' => 'array',
39+
'options' => 'array',
40+
'preferences' => 'json',
3541
];
3642

3743
public function getGreetingAttribute()
@@ -81,6 +87,17 @@ public function testGetArrayAttribute(): void
8187
$this->assertTrue($this->model->getContent('options.skills.php'));
8288
}
8389

90+
public function testGetJsonAttribute(): void
91+
{
92+
$this->assertIsArray($this->model->getContent('preferences.notifications'));
93+
$this->assertArrayHasKey('email', $this->model->getContent('preferences.notifications'));
94+
$this->assertTrue($this->model->getContent('preferences.notifications.email'));
95+
$this->assertFalse($this->model->getContent('preferences.notifications.sms'));
96+
97+
$this->assertIsString($this->model->getContent('preferences.theme'));
98+
$this->assertSame('dark', $this->model->getContent('preferences.theme'));
99+
}
100+
84101
public function testGetRelation(): void
85102
{
86103
$this->assertIsInt($this->model->getContent('many.three'));

0 commit comments

Comments
 (0)