承接 ekiwok/quick-fixtures 相关项目开发

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

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

ekiwok/quick-fixtures

Composer 安装命令:

composer require ekiwok/quick-fixtures

包简介

Generate complex fixtures based on @var annotations.

README 文档

README

  • Did you ever add unnecessary setter because you didn't want to use reflections in fixtures?
  • Did you give up on using value objects because writing fixtures this way was messy?
  • Did you create trait to help with \DateTime creation in fixtures?

If anything above applies to you you may find this helpful.

This small library may quickly generate fixtures for you based on dockblock annotations that probably already are present in your code.

Provided generator accepts associative arrays so you may keep your fixtures data in file of your choice. It might be yaml, xml, csv, etc...

Fe. prepare yaml file like this:

    "Jake Weary":
        uuid: "123e4567-e89b-12d3-a456-426655440000"
        name: "Jake Weary"
        email: "jake.weary@example.com"
        # Notice that for single property objects it's ok to skip property name
        credit: 100

And just use this data to generate fixture:

    $jakeWearyData = /* fetch "Jake Weary" entry from yml */

    $jakeWeary = $generator->generate(Customer::class, $jakeWearyData);

Instead of writing:

    $jakeWeary = new Customer(
        '123e4567-e89b-12d3-a456-426655440000',
        'Jake Weary',
        'jake.weary@example.com',
        new Credit(100),
    );

or:

    $jakeWeary = (new Customer())
        ->setUUID('123e4567-e89b-12d3-a456-426655440000')
        ->setName('Jake Weary')
        ->setEmail'jake.weary@example.com')
        ->setCredit(new Credit(100))
    ;

Installation

Install with composer: composer require ekiwok/quick-fixtures

Extending

It's easily extendable by adding your own processors.

    $generator->addProcessor(new class implements \Ekiwok\QuickFixtures\Processor\PrioritisedProcessorInterface{
    
        public function getPriority()
        {
            return 1025;
        }
    
        public function process(\Ekiwok\QuickFixtures\ContextInterface $context, $payload, \Ekiwok\QuickFixtures\GeneratorInterface $generator)
        {
            return new \DateTime($payload);
        }
    
        public function applies(\Ekiwok\QuickFixtures\ContextInterface $context, $payload)
        {
            $type = $context->getType();
            
            // in real life we would also check payload to be sure it
            // also makes sense
    
            return $type->hasAnyClass()
                && $type->hasClass(\DateTime::class);
        }
    });

Processor with this priority will be run before built in processors and will set all properties these are marked as @var \DateTime.

Documentation

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固