mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-27 04:45:26 +01:00
test: add test case for scopes
This commit is contained in:
parent
72c74de915
commit
402ad73244
@ -44,4 +44,15 @@ final class User extends Model {
|
|||||||
{
|
{
|
||||||
return $this->morphOne(Image::Class, 'imageable');
|
return $this->morphOne(Image::Class, 'imageable');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scope a query to only include active users.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||||
|
* @return \Illuminate\Database\Eloquent\Builder
|
||||||
|
*/
|
||||||
|
public function scopeActive($query)
|
||||||
|
{
|
||||||
|
return $query->where('active', 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
38
tests/acceptance/EloquentModelTypes.feature
Normal file
38
tests/acceptance/EloquentModelTypes.feature
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Feature: Eloquent Relation Types
|
||||||
|
Illuminate\Database\Eloquent\Relations have type support
|
||||||
|
|
||||||
|
Background:
|
||||||
|
Given I have the following config
|
||||||
|
"""
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<psalm totallyTyped="true">
|
||||||
|
<projectFiles>
|
||||||
|
<directory name="."/>
|
||||||
|
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
|
||||||
|
</projectFiles>
|
||||||
|
<plugins>
|
||||||
|
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
|
||||||
|
</plugins>
|
||||||
|
</psalm>
|
||||||
|
"""
|
||||||
|
And I have the following code preamble
|
||||||
|
"""
|
||||||
|
<?php declare(strict_types=1);
|
||||||
|
namespace Tests\Psalm\LaravelPlugin\Sandbox;
|
||||||
|
|
||||||
|
use Tests\Psalm\LaravelPlugin\Models\User;
|
||||||
|
"""
|
||||||
|
|
||||||
|
Scenario: Model scope support
|
||||||
|
Given I have the following code
|
||||||
|
"""
|
||||||
|
|
||||||
|
function test(): \Illuminate\Database\Eloquent\Collection
|
||||||
|
{
|
||||||
|
return User::active()->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
When I run Psalm
|
||||||
|
Then I see no errors
|
||||||
|
|
Loading…
Reference in New Issue
Block a user