1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 00:17:31 +02:00

Fix Callables for Extenders (#2423)

- Standardize signatures and variable names for extenders that take callbacks
- Adjust model extender docblock to clarify that default calue can't be an invokable class.
- Make invokable classes provided to Model->relationship
- Add integration tests to ensure Model->relationship and User->groupProcessor extenders accept callbacks
- Extract code for wrapping callbacks into central util
This commit is contained in:
Alexander Skvortsov
2020-11-08 21:36:38 -05:00
committed by GitHub
parent c10cc92deb
commit 47d2eee9ce
10 changed files with 108 additions and 39 deletions

View File

@@ -134,6 +134,23 @@ class ModelTest extends TestCase
$this->assertEquals([], $user->customRelation()->get()->toArray());
}
/**
* @test
*/
public function custom_relationship_can_be_invokable_class()
{
$this->extend(
(new Extend\Model(User::class))
->relationship('customRelation', CustomRelationClass::class)
);
$this->prepDB();
$user = User::find(1);
$this->assertEquals([], $user->customRelation()->get()->toArray());
}
/**
* @test
*/
@@ -423,3 +440,11 @@ class ModelTestCustomPost extends AbstractEventPost
*/
public static $type = 'customPost';
}
class CustomRelationClass
{
public function __invoke(User $user)
{
return $user->hasMany(Discussion::class, 'user_id');
}
}