定制 rnr/laravel-alice 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

rnr/laravel-alice

Composer 安装命令:

composer require rnr/laravel-alice

包简介

Wrapper of alice fixture generator for laravel

README 文档

README

Package version Build Status

A Laravel package to manage fixtures with nelmio/alice.

Installation

This is installable via Composer as rnr/laravel-alice

composer install --dev rnr/laravel-alice

Basic usage

Create yml fixture file as it is described nelmio/alice

Nelmio\Entity\User:
    user{1..10}:
        username: '<username()>'
        fullname: '<firstName()> <lastName()>'
        birthDate: '<date()>'
        email: '<email()>'
        favoriteNumber: '50%? <numberBetween(1, 200)>'

Nelmio\Entity\Group:
    group1:
        name: Admins
        owner: '@user1'
        members: '<numberBetween(1, 10)>x @user*'
        created: '<dateTimeBetween("-200 days", "now")>'
        updated: '<dateTimeBetween($created, "now")>'

Class FixturelLoader has one significant method load to load models. That method receive one or array of files with data to load. You can load this fixture to database with next code:

<?php
namespace Rnr\Tests\Alice;

use Orchestra\Testbench\TestCase as ParentTestCase;
use Rnr\Alice\FixturesLoader;
use Nelmio\Entity\User;
use Nelmio\Entity\Group;

class TestCase extends ParentTestCase
{
    /** @var FixturesLoader */
    protected $fixturesLoader;

    protected function setUp()
    {
        parent::setUp();

        $this->fixturesLoader = $this->app->make(FixturesLoader::class);
    }
    
    public function testLoadingFixtures() {
        $objects = $this->fixturesLoader->load('fixture.yml');
        
        $users = User::all();
        
        $this->assertEquals(array_map($objects, function ($model) {
            return $model->getKey();
        }), $users->modelKeys());
    }
}

It loads data for next models:

<?php
namespace Nelmio\Entity;

use Illuminate\Database\Eloquent\Model;

class User extends Model  {
    protected $table = 'users';
}

class Group extends Model {
    protected $table = 'groups';
    
    public function owner() {
        return $this->belnogsTo(User::class);
    }
}

Restrictions

You can use id to specify related models in relationships, but these models should be already create in database.

Extracting fixtures from database

If you add GenerateFixtureCommand to your console kernel you can export data to yml from existing database. This class add new command db:generate-fixture to artisan. This command extract fixtures from database. Command takes array of models with relations in specific format:

php artisan db:generate-fixture \
    'Nelmio\Entity\User(relations:relation1,realation2.subrelation)=1,2,3-5,17,20-25' \
    'Nelmio\Entity\Group(relations:hasOne)=*' > /path/to/fixture.yml

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固