tarawski / fixtures
帮助管理PHP项目中 fixtures 的工具
dev-master
2018-04-18 19:59 UTC
Requires
- php: ^7.1
- symfony/yaml: ^4.0
Requires (Dev)
- phpmd/phpmd: ^2.6
- phpspec/phpspec: ^4.2
- phpunit/phpunit: ^7.0
- sebastian/phpcpd: ^4.0
- squizlabs/php_codesniffer: ^3.2
This package is auto-updated.
Last update: 2024-09-15 00:29:26 UTC
README
帮助管理PHP项目中 fixtures 的工具
安装
$ composer require tarnawski/fixtures
支持的 fixtures 文件类型
YAML
document: - id: 1 name: Secret document status: draft - id: 2 name: Other document status: published
JSON
{ "document": [ { "id": "1", "name": "Secret document", "status": "draft" }, { "id": "2", "name": "Other document", "status": "published" } ] }
XML
<?xml version="1.0" encoding="UTF-8"?> <fixtures> <document> <id>1</id> <name>Secret document</name> <status>draft</status> </document> <document> <id>2</id> <name>Other document</name> <status>published</status> </document> </fixtures>
独立使用
$loader = new FileLoader(); $parser = new JSONParser(); $driver = new PDODriver('database', 'host', 'port', 'user', 'passoword'); $fixtureBuilder = new FixtureBuilder($loader, $parser, $driver); $fixtureBuilder->load('fixtures/document.json');
与 Symfony 一起使用
- 启用 Bundle
$bundles = array( new Fixture\Bridge\Symfony\FixtureBundle(), );
- 配置 Bundle
fixture: path: '%kernel.project_dir%/fixtures/document.json' loader: 'file' parser: 'json' driver: 'pdo'
- 运行命令
php bin/console fixture:load