kununu/data-fixtures
Composer 安装命令:
composer require kununu/data-fixtures
包简介
Load data fixtures in your application for any storage
README 文档
README
At kununu we rely on data fixtures in our tests as well in our development and testing environments. A good definition of what fixtures are is the one from the documentation of DoctrineFixturesBundle in which the design and implementation of this package was heavily based on.
Fixtures are used to load a “fake” set of data into a database that can then be used for testing or to help give you some interesting data while you’re developing your application.
What is kununu/data-fixtures?
This package provides a simple way to manage and execute the loading of data fixtures for any storage mechanism.
Its design and implementation was heavily based on the Doctrine data-fixtures package.
If you are interested in why we created this package check out Why kununu/data-fixtures?.
Fixtures types
Currently, this package supports the following types of fixtures:
- Doctrine DBAL Connection Fixtures which relies on Doctrine DBAL by using the Connection implementation
- Cache Pool Fixtures which relies on implementations of the PSR-6 standard
- DynamoDB Fixtures which relies on the AWS SDK for PHP DynamoDB client
- Elasticsearch Fixtures which relies on the Elasticsearch-PHP client
- OpenSearch Fixtures which relies on the OpenSearch PHP client
- Symfony Http Client Fixtures which relies on the Symfony Http Client and Symfony Http Foundation.
Also check Directory Loader to check how to load fixtures from files in a directory.
If you are interested in knowing more about the concepts of the package, or you need to create a new fixture type check out How to create a new Fixture Type.
Install
1. Add kununu/data-fixtures to your project
Before installing this package be aware:
- You own the fixtures you load
- This package should not be used in production mode!
composer require --dev kununu/data-fixtures
2. Enable any fixture type
In order to enable the fixture types that you are interested, check out their documentation:
- Doctrine DBAL Connection Fixtures
- Cache Pool Fixtures
- DynamoDB Fixtures
- Elasticsearch Fixtures
- OpenSearch Fixtures
- Symfony Http Client Fixtures
Append Fixtures
By default, when loading fixtures the data storage is purged. If you want to change this behavior and instead append the fixtures you can pass false as second argument to any executor.
// By default, the data storage is purged $executor->execute($loader->getFixtures()); // If you want you can `append` the fixtures instead of purging the database $executor->execute($loader->getFixtures(), true);
Load Fixtures
In order to load fixtures the default Loader provides a couple of options:
loadFromDirectory(string $dir)loadFromFile(string $fileName)loadFromClassName(string $className)addFixture(FixtureInterface $fixture)
<?php declare(strict_types=1); use Kununu\DataFixtures\Loader\ConnectionFixturesLoader; $loader = new ConnectionFixturesLoader(); $loader->loadFromDirectory('/your/directory/'); $loader->loadFromFile('/your/file.php'); $loader->loadFromClassName(MyFixtureSql::class); $loader->addFixture(new MyFixtureSql());
Initializable Fixtures
If you want your Fixture classes to be initialized you can implement the InitializableFixtureInterface
public function initializeFixture(mixed ...$args): void;
Then before loading the fixtures you need to register them in the Loader:
<?php declare(strict_types=1); use Kununu\DataFixtures\Loader\ConnectionFixturesLoader; $loader = new ConnectionFixturesLoader(); $this->loader->registerInitializableFixture( YourFixtureClass::class, // 1st argument 1, // 2nd argument 'This is an argument that will be passed to initializeFixture of YourFixtureClass', // 3rd argument [ 'field' => 'field-name', 'value' => 10, ], // 4th argument $anInstanceOfOneOfYourOtherClasses // Pass as many arguments as you like... ); $loader->addFixture(new YourFixtureClass());
Contribute
If you are interested in contributing read our contributing guidelines.
Tests
If not yet, first install composer dependencies:
composer install
Run the tests by doing:
vendor/bin/phpunit
To run tests without coverage report:
composer install
composer test
To run tests with coverage report:
composer install composer test-coverage
kununu/data-fixtures 适用场景与选型建议
kununu/data-fixtures 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74.42k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 05 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「doctrine」 「Data fixtures」 「elasticsearch」 「dynamodb」 「opensearch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kununu/data-fixtures 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kununu/data-fixtures 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kununu/data-fixtures 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Dibi is Database Abstraction Library for PHP
Store your language lines in the database, yaml or other sources
Adds the EDTF data type to Wikibase
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
A simple library that allows transform any kind of data to native php data or whatever
统计信息
- 总下载量: 74.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 39
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-07