定制 krajcik/data-builder 二次开发

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

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

krajcik/data-builder

最新稳定版本:v1.0.2

Composer 安装命令:

composer require krajcik/data-builder

包简介

Data generator based on database structure of your project.

README 文档

README

Package helps to write test data for tests using data builders which package generate specifically for your project. By default, are all data filled randomly with option change one or more properties.

Installation

composer require krajcik/data-builder

Using

Configuration and generate

    use \Krajcik\DataBuilder\Dto\Configuration;
    
    $targetFolder = '../tests/generated'; // specify some path in your project where you want generate builders

    $configuration = new Configuration(
        $targetFolder,
        'localhost',
        'myTestDb',
        'root',
        'root',
    );

Define builders which want generate

Define all doctrine entities for which you want generate builder

    use \Krajcik\DataBuilder\Dto\BuilderToGenerateDto;

    $builderToGenerate = [
        BuilderToGenerateDto::createFromDoctrineEntity('Api\Contact\Entity\Contact'),
        BuilderToGenerateDto::createFromDoctrineEntity('Api\Contact\Entity\ContactData'),
    ];

Generate builders

    use \Krajcik\DataBuilder\BuilderCompiler;

    $compiler = new BuilderCompiler($configuration);
    $compiler->compile($builderToGenerate);

Using builders

    $builderFactory = new \Tests\Generated\Builder\BuilderFactory($entityManager);

    $contactData = $builderFactory->createContactDataBuilder()
        ->withFirstName('John')
        ->withLastName('Doe')
        ->buildAndSave();
    // $contactData is saved entity (Api\Contact\Entity\ContactData) from your project which you can use now in your test case

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2024-08-04