Fix failing tests for firstOrCreate and firstOrNew in Laravel 9

This commit is contained in:
Martin Zurowietz 2022-04-26 13:39:37 +02:00
parent e50f7f0574
commit 48d1c56b46
2 changed files with 38 additions and 1 deletions

View File

@ -167,6 +167,20 @@ class Builder
*/ */
public function firstOr($columns = ['*'], Closure $callback = null) { } public function firstOr($columns = ['*'], Closure $callback = null) { }
/**
* @param array $attributes
* @param array $values
* @return TModel|self<TModel>
*/
public function firstOrNew(array $attributes = [], array $values = []) { }
/**
* @param array $attributes
* @param array $values
* @return TModel|self<TModel>
*/
public function firstOrCreate(array $attributes = [], array $values = []) { }
/** /**
* @param string $column * @param string $column
* @return mixed * @return mixed

View File

@ -178,7 +178,7 @@ Feature: Eloquent Builder types
Then I see no errors Then I see no errors
Scenario: can call firstOrNew and firstOrCreate without parameters in Laravel 8.x Scenario: can call firstOrNew and firstOrCreate without parameters in Laravel 8.x
Given I have the "laravel/framework" package satisfying the ">= 8.0" Given I have the "laravel/framework" package satisfying the "^8.0"
And I have the following code And I have the following code
""" """
/** /**
@ -200,6 +200,29 @@ Feature: Eloquent Builder types
When I run Psalm When I run Psalm
Then I see no errors Then I see no errors
Scenario: can call firstOrNew and firstOrCreate without parameters in Laravel 9.x
Given I have the "laravel/framework" package satisfying the "^9.0"
And I have the following code
"""
/**
* @psalm-param Builder<User> $builder
* @psalm-return Builder<User>|User
*/
function test_firstOrCreate(Builder $builder): Builder|User {
return $builder->firstOrCreate();
}
/**
* @psalm-param Builder<User> $builder
* @psalm-return Builder<User>|User
*/
function test_firstOrNew(Builder $builder): Builder|User {
return $builder->firstOrNew();
}
"""
When I run Psalm
Then I see no errors
Scenario: can call whereDate with \DateTimeInterface|string|null Scenario: can call whereDate with \DateTimeInterface|string|null
Given I have the following code Given I have the following code
""" """