Skip to content

Commit 0fd2e4f

Browse files
committed
add type assertion test for query builder for
1 parent 7f42132 commit 0fd2e4f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ parameters:
88
- src/
99
- config/
1010
- database/
11+
- types/
1112

1213
# Level 9 is the highest level
1314
level: 5

types/query-builder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use Illuminate\Database\Eloquent\Model;
4+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
5+
use Spatie\QueryBuilder\QueryBuilder;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Book extends Model {
9+
/**
10+
* @return BelongsTo<Author, $this>
11+
*/
12+
public function author(): BelongsTo
13+
{
14+
return $this->belongsTo(Author::class);
15+
}
16+
}
17+
18+
class Author extends Model {}
19+
20+
assertType('Spatie\QueryBuilder\QueryBuilder<Book>', QueryBuilder::for(Book::class));
21+
assertType('Spatie\QueryBuilder\QueryBuilder<Book>', QueryBuilder::for(Book::query()));
22+
assertType('Spatie\QueryBuilder\QueryBuilder<Author>', QueryBuilder::for((new Book)->author()));

0 commit comments

Comments
 (0)