paasky/laravel-model-test 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

paasky/laravel-model-test

最新稳定版本:v0.1.6

Composer 安装命令:

composer require paasky/laravel-model-test

包简介

Tests Eloquent Model instances and relations

README 文档

README

Trait to test that all your Laravel Models are instances of correct classes and all relations work

Installation

composer require paasky/laravel-model-test --dev

Usage

In any PHPUnit test

use Paasky\TestsModels;

class MyTest extends TestCase
{
    use RefreshDatabase, TestsModels;
    
    public function testModels()
    {
        $this->assertModels();
    }
}

Configuration

Configurations are public attributes of the TestsModels-Trait

modelPaths

Full path(s) to look in for Model classes, includes sub-folders.
Default: [app_path('Models')]

  • $this->modelPaths = [app_path('Models'), app_path('SuperCoolModels')];
  • Tip: If your models are directly in app, you can skip auto-discovery and pass an array of classes to assertModels():
    $this->assertModels([User::class, SomethingElse::class, ...]);

allowedInstances

Classes that found classes can be an instance of. Useful if your project has a custom Model-class.
Default: [Model::class]

  • $this->allowedInstances = [ProjectModel::class];

allowNonModels

Skip or fail classes that are not instances of Illuminate\Database\Eloquent\Model
Default: false (Fail)

  • $this->allowNonModels = true;

requiredInstancePerModel

Override allowedInstances for specific classes by setting the required instance.
Default: ['App\User' => Authenticatable::class, 'App\Models\User' => Authenticatable::class]

  • $this->requiredInstancePerModel[SimpleUser::class] = Model::class;

ignoreMethodsPerNamespace

Ignore these methods from validation, useful when packages don't typehint the return type and are failing
Use '*' to ignore all methods in the namespace
Default: ['Illuminate\\' => ['*']

  • $this->ignoreMethodsPerNamespace['SomeDude\\Package\\'] = ['dumbMethod'];

enableBackRelationValidation

Should back relations (eg User has Post, so Post must have User) be validated
Default: true

  • $this->enableBackRelationValidation = false;

enableBackRelationTypeValidation

Should back relation return types (eg User HasMany Posts, so Post must BelongTo User) be validated
Default: true

  • $this->enableBackRelationTypeValidation = false;

skipBackRelationMethodsValidationPerModel

Methods to skip for back relation validation
Use '*' to ignore all methods of the class
Default: ['App\User' => ['tokens'], 'App\Models\User' => ['tokens']]

  • $this->skipBackRelationMethodsValidationPerModel[PivotModel::class] = ['*'];

统计信息

  • 总下载量: 25
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-04-21