承接 betapeak/laravel-testing-helper-traits 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

betapeak/laravel-testing-helper-traits

Composer 安装命令:

composer require --dev betapeak/laravel-testing-helper-traits

包简介

Adds traits similar to the DatabaseMigtaions trait, but with added seeding.

README 文档

README

The included trait provides additional features on top of the existing DatabaseMigrations trait currently included with Laravel:

  • Using 'migrate:refresh' instead of the hardcoded 'migrate:fresh' by including a property on your test class
protected $useRefreshMigrations = true;
  • Using custom seeders which can be defined separately for each test
protected $seederClass = 'AnotherDatabaseSeeder';

Installation

This package requires that you are using laravel/framework: 5.5.*. Provided this is fulfilled, you can install the helper traits like so:

composer require betapeak/laravel-testing-helper-traits

Usage

You can use the included DatabaseMigrationsWithSeeding trait in place of the existing DatabaseMigrations trait included in Laravel. Like the default trait, it will migrate:fresh the database, but will also seed it with the default DatabaseSeeder class.

namespace Tests;
use BetaPeak\Testing\Traits\DatabaseMigrationsWithSeeding;

class SomeUnitTest extends TestCase
{
    use DatabaseMigrationsWithSeeding;
    

    /** @test */
    public function it_tests_something()
    {
        //Test something
    }
    
}

You can specify a different seeder class like so:

namespace Tests;
use BetaPeak\Testing\Traits\DatabaseMigrationsWithSeeding;

class SomeUnitTest extends TestCase
{
    use DatabaseMigrationsWithSeeding;
    
    protected $seederClass = 'AnotherSeederClass';

    ...
    
}

Finally, if you don't want to use migrate:fresh, you can force the trait to use migrate:refresh like so:

namespace Tests;
use BetaPeak\Testing\Traits\DatabaseMigrationsWithSeeding;

class SomeUnitTest extends TestCase
{
    use DatabaseMigrationsWithSeeding;
    
    protected $useRefreshMigrations = true;

    ...
    
}

More information on using database migrations in tests can be found on Laravel's homepage

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固