mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-11-30 04:39:01 +01:00
chore: make test models and load them so we can test ide helper things
This commit is contained in:
parent
4dce5e65cc
commit
db44a11bfc
@ -31,6 +31,11 @@
|
||||
"Psalm\\LaravelPlugin\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Tests\\Psalm\\LaravelPlugin\\": "tests"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"check": [
|
||||
"@analyze",
|
||||
@ -45,7 +50,7 @@
|
||||
"codeception/codeception": "4.1.x-dev#93a699972a8578bb463d8687b6c87ed7ebadf38a as 4.1.6",
|
||||
"codeception/module-phpbrowser": "^1.0.0",
|
||||
"codeception/module-asserts": "^1.0.0",
|
||||
"weirdan/codeception-psalm-module": "^0.7.1",
|
||||
"weirdan/codeception-psalm-module": "^0.7.2",
|
||||
"squizlabs/php_codesniffer": "*",
|
||||
"slevomat/coding-standard": "^6.2"
|
||||
}
|
||||
|
@ -98,5 +98,12 @@ final class ApplicationHelper
|
||||
protected function getEnvironmentSetUp($app): void
|
||||
{
|
||||
$app['config']->set('app.key', 'AckfSECXIvnK5r28GVIWUAxmbBSjTsmF');
|
||||
|
||||
// in testing, we want ide-helper to load our test models. Unfortunately this has to be a relative path, with
|
||||
// the base path being inside of orchestra/testbench-core/laravel
|
||||
|
||||
$app['config']->set('ide-helper.model_locations', [
|
||||
'../../../../tests/Models',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class FakeModelsCommand extends \Barryvdh\LaravelIdeHelper\Console\ModelsCommand
|
||||
/** @return array<class-string> */
|
||||
public function getModels()
|
||||
{
|
||||
return $this->model_classes;
|
||||
return $this->model_classes + $this->loadModels();
|
||||
}
|
||||
|
||||
/**
|
||||
|
9
tests/Models/Car.php
Normal file
9
tests/Models/Car.php
Normal file
@ -0,0 +1,9 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
final class Car extends Model {
|
||||
protected $table = 'cars';
|
||||
};
|
17
tests/Models/Comment.php
Normal file
17
tests/Models/Comment.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
final class Comment extends Model
|
||||
{
|
||||
/**
|
||||
* @psalm-return BelongsTo<Post>
|
||||
*/
|
||||
public function post(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
}
|
18
tests/Models/Image.php
Normal file
18
tests/Models/Image.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
|
||||
final class Image extends Model
|
||||
{
|
||||
/**
|
||||
* Get the owning imageable model.
|
||||
*/
|
||||
public function imageable(): MorphTo
|
||||
{
|
||||
return $this->morphTo();
|
||||
}
|
||||
}
|
18
tests/Models/Mechanic.php
Normal file
18
tests/Models/Mechanic.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||
|
||||
final class Mechanic extends Model {
|
||||
protected $table = 'mechanics';
|
||||
|
||||
/**
|
||||
* @psalm-return HasOneThrough<User>
|
||||
*/
|
||||
public function carOwner(): HasOneThrough
|
||||
{
|
||||
return $this->hasOneThrough(User::class, Car::class);
|
||||
}
|
||||
}
|
18
tests/Models/Phone.php
Normal file
18
tests/Models/Phone.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
final class Phone extends Model {
|
||||
protected $table = 'phone_numbers';
|
||||
|
||||
/**
|
||||
* @psalm-return BelongsTo<User>
|
||||
*/
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
26
tests/Models/Post.php
Normal file
26
tests/Models/Post.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
final class Post extends Model {
|
||||
protected $table = 'posts';
|
||||
|
||||
/**
|
||||
* @psalm-return HasMany<Comment>
|
||||
*/
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(Comment::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return MorphOne<Image>
|
||||
*/
|
||||
public function image(): MorphOne
|
||||
{
|
||||
return $this->morphOne(Image::class, 'imageable');
|
||||
}
|
||||
}
|
18
tests/Models/Role.php
Normal file
18
tests/Models/Role.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
final class Role extends Model {
|
||||
protected $table = 'roles';
|
||||
|
||||
/**
|
||||
* @psalm-return BelongsToMany<User>
|
||||
*/
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class);
|
||||
}
|
||||
}
|
44
tests/Models/User.php
Normal file
44
tests/Models/User.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
final class User extends Model {
|
||||
protected $table = 'users';
|
||||
|
||||
/**
|
||||
* @psalm-return HasOne<Phone>
|
||||
*/
|
||||
public function phone(): HasOne
|
||||
{
|
||||
return $this->hasOne(Phone::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return BelongsToMany<Role>
|
||||
*/
|
||||
public function roles(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Role::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-return HasManyThrough<Mechanic>
|
||||
*/
|
||||
public function carsAtMechanic(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Mechanic::class, Car::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's image.
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
return $this->morphOne(Image::Class, 'imageable');
|
||||
}
|
||||
}
|
@ -21,9 +21,7 @@ Feature: Database Builder Types
|
||||
"""
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
final class User extends \Illuminate\Database\Eloquent\Model {
|
||||
protected $table = 'users';
|
||||
};
|
||||
use Tests\Psalm\LaravelPlugin\Models\User;
|
||||
|
||||
final class UserRepository
|
||||
{
|
||||
|
@ -21,9 +21,7 @@ Feature: Eloquent Builder Types
|
||||
"""
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
final class User extends \Illuminate\Database\Eloquent\Model {
|
||||
protected $table = 'users';
|
||||
};
|
||||
use Tests\Psalm\LaravelPlugin\Models\User;
|
||||
|
||||
final class UserRepository
|
||||
{
|
||||
|
@ -23,9 +23,7 @@ Feature: Eloquent Collection Types
|
||||
|
||||
namespace Tests\Psalm\LaravelPlugin\Models;
|
||||
|
||||
class User extends \Illuminate\Database\Eloquent\Model {
|
||||
protected $table = 'users';
|
||||
};
|
||||
use Tests\Psalm\LaravelPlugin\Models\User;
|
||||
|
||||
final class UserRepository
|
||||
{
|
||||
|
@ -21,9 +21,7 @@ Feature: Factory Types
|
||||
"""
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
class User extends \Illuminate\Database\Eloquent\Model {
|
||||
protected $table = 'users';
|
||||
};
|
||||
use Tests\Psalm\LaravelPlugin\Models\User;
|
||||
|
||||
class FactoryTest {
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user