test: add test case for scopes

This commit is contained in:
fiachra mcdermott 2021-07-04 13:51:08 -04:00
parent 72c74de915
commit 402ad73244
2 changed files with 49 additions and 0 deletions

View File

@ -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);
}
} }

View 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