mirror of
https://github.com/flarum/core.git
synced 2025-08-09 09:57:06 +02:00
feat(phpstan): foundation for usage in extensions (#3666)
* feat(phpstan): pick up extended model relations typings * feat(phpstan): pick up extended model date attributes * feat(core): introduce `castAttribute` extender Stops using `dates` as it's deprecated in laravel 8 * feat(phpstan): pick up extended model attributes through casts * fix: extenders not resolved when declared namespace * fix(phpstan): new model attributes are always nullable * chore(phpstan): add helpful cache clearing command * Apply fixes from StyleCI * chore: improve extend files provider logic * chore: rename `castAttribute` to just `cast` * chore: update phpstan package to detect `cast` method * Update framework/core/src/Extend/Model.php Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
@@ -375,64 +375,64 @@ class ModelTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_date_attribute_doesnt_exist_by_default()
|
||||
public function custom_cast_attribute_doesnt_exist_by_default()
|
||||
{
|
||||
$post = new Post;
|
||||
|
||||
$this->app();
|
||||
|
||||
$this->assertNotContains('custom', $post->getDates());
|
||||
$this->assertFalse($post->hasCast('custom'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_date_attribute_can_be_set()
|
||||
public function custom_cast_attribute_can_be_set()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Model(Post::class))
|
||||
->dateAttribute('custom')
|
||||
->cast('custom', 'datetime')
|
||||
);
|
||||
|
||||
$this->app();
|
||||
|
||||
$post = new Post;
|
||||
|
||||
$this->assertContains('custom', $post->getDates());
|
||||
$this->assertTrue($post->hasCast('custom', 'datetime'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_date_attribute_is_inherited_to_child_classes()
|
||||
public function custom_cast_attribute_is_inherited_to_child_classes()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Model(Post::class))
|
||||
->dateAttribute('custom')
|
||||
->cast('custom', 'boolean')
|
||||
);
|
||||
|
||||
$this->app();
|
||||
|
||||
$post = new CommentPost;
|
||||
|
||||
$this->assertContains('custom', $post->getDates());
|
||||
$this->assertTrue($post->hasCast('custom', 'boolean'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function custom_date_attribute_doesnt_work_if_set_on_unrelated_model()
|
||||
public function custom_cast_attribute_doesnt_work_if_set_on_unrelated_model()
|
||||
{
|
||||
$this->extend(
|
||||
(new Extend\Model(Post::class))
|
||||
->dateAttribute('custom')
|
||||
->cast('custom', 'integer')
|
||||
);
|
||||
|
||||
$this->app();
|
||||
|
||||
$discussion = new Discussion;
|
||||
|
||||
$this->assertNotContains('custom', $discussion->getDates());
|
||||
$this->assertFalse($discussion->hasCast('custom', 'integer'));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user