trendwerk / faker
使用 WP-CLI 生成假数据。
0.1.3
2019-02-08 11:04 UTC
Requires
- php: ^5.6 || ^7.0
- fzaninotto/faker: ^1.8
- nelmio/alice: ^2.2
- wp-cli/wp-cli: ^2.0
Requires (Dev)
- behat/behat: ^2.5
- squizlabs/php_codesniffer: ^2.9
This package is auto-updated.
Last update: 2024-09-08 23:55:29 UTC
README
使用 wp-cli 生成假帖子数据。专为 WordPress 设计。
依赖于 nelmio/alice 和 fzaninotto/Faker。
通过 5queezer/faker 增强了用户能力。
安装
wp package install trendwerk/faker
需要 wp-cli >= 2.0。
使用方法
wp faker fake <files>...
选项
删除数据
wp faker delete
删除所有假数据。
支持
YAML 文件支持
YAML / Faker
您的 YAML 文件可能如下所示。
要了解内部结构
- YAML 文件由 nelmio/alice 解释;
- 任何来自 fzaninotto/Faker 的函数都可用;
- 此外,此库还提供了
<terms>
函数。
基本
Trendwerk\Faker\Entity\Post: post{1..100}: post_content: <paragraphs(4, true)> post_title: '<sentence()>'
生成 100 篇帖子,包含标题和内容。
帖子类型
Trendwerk\Faker\Entity\Post: post{1..100}: post_title: '<sentence()>' post_type: 'testimonials'
生成 100 篇帖子类型为 testimonials
的帖子,包含标题。
元数据
Trendwerk\Faker\Entity\Post: post{1..100}: post_title: '<sentence()>' post_type: 'testimonials' meta: name: '<name()>' address: '<address()>'
生成 100 篇包含标题和自定义字段 name
及 address
的评论。
术语
Trendwerk\Faker\Entity\Post: post{1..100}: post_content: <paragraphs(3, true)> post_title: '<sentence()>' terms: category: <terms('category', 1)> post_tag: <terms('post_tag', 7)>
生成 100 篇帖子,包含标题、内容、1 个随机分类和 7 个随机标签。
使用 <terms>
不是必需的。您也可以提供整数数组或使用 randomElements。
选项
ACF
Trendwerk\Faker\Entity\Post: post{1..100}: post_content: <paragraphs(3, true)> post_title: '<sentence()>' acf: name: '<name()>' address: '<address()>'
生成 100 篇帖子,包含标题、内容,以及两个填充的 ACF 字段: name
和 address
。
重复字段名称
在 ACF 中,可能存在多个具有相同名称的字段。这可能会导致使用此库生成数据时格式化冲突。如果您有两个具有相同名称的字段,建议使用唯一的字段键
Trendwerk\Faker\Entity\Post: post{1..100}: post_content: <paragraphs(3, true)> post_title: '<sentence()>' acf: field_56cf2f782e9b1: '<name()>' # Name address: '<address()>'
用户
Trendwerk\Faker\Entity\User: user{1..10}: user_login: '<username()>' user_pass: '<username()>' first_name: '<firstName()>' last_name: '<lastName()>' display_name: '<firstName()> <lastName()>' user_email: '<email()>' role: 'author'
生成 10 个具有作者角色的用户。
附件
目前支持的附件类型仅为图像。
图像
Trendwerk\Faker\Entity\Image: image{1..3}: data: '<image()>'
生成 3 个图像附件。图像由 Faker 提供,而 LoremPixel 提供了 Faker。
帖子 + (特色) 图像 + 用户
# image.yml Trendwerk\Faker\Entity\Image: image{1..3}: data: '<image()>'
# user.yml Trendwerk\Faker\Entity\User: user{1..10}: user_login: '<username()>' user_pass: '<username()>' user_email: '<email()>' role: 'author'
# post.yml Trendwerk\Faker\Post: post{1..1}: post_content: <paragraphs(3, true)> post_title: '<sentence()>' post_author: '@user*->id' meta: _thumbnail_id: '@image*->id'
现在您可以将所有三个文件提供给 wp faker fake
wp faker fake image.yml user.yml post.yml
确保首先加载包含引用对象的文件。