Skip to content

Commit

Permalink
Fix "Segmentation fault" for model inheritance (#109)
Browse files Browse the repository at this point in the history
* Fix "Segmentation fault" for model inheritance

* Fix formatting
  • Loading branch information
mistermij committed Sep 20, 2023
1 parent 2fe95e4 commit b924e6a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Traits/HasSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __call($name, $args)
return $this->settings();
}

return call_user_func(get_parent_class($this) . '::__call', $name, $args);
return call_user_func(parent::class . '::__call', $name, $args);
}

abstract public function getSettingsValue(): array;
Expand Down
10 changes: 10 additions & 0 deletions tests/Models/UsersWithParentModelWithField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Glorand\Model\Settings\Tests\Models;

class UsersWithParentModelWithField extends UserWithTextField
{
protected $table = 'users_with_field';

protected $fillable = ['id', 'name'];
}
23 changes: 23 additions & 0 deletions tests/ParentChildSettingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Glorand\Model\Settings\Tests;

use Glorand\Model\Settings\Tests\Models\UsersWithParentModelWithField;
use Glorand\Model\Settings\Tests\Models\UserWithField as User;

class ParentChildSettingsTest extends TestCase
{
public function setUp(): void
{
parent::setUp();
$this->model = UsersWithParentModelWithField::first();
}

public function testSettingsForChild()
{
$testArray = ['a' => 'b'];
$this->model->settings = $testArray;
$this->model->save();
$this->assertEquals($this->model->settings()->all(), $testArray);
}
}

0 comments on commit b924e6a

Please sign in to comment.