在 YML 夹具文件中生成数据(使用 PHP)
我想为夹具文件生成测试数据。我想要生成测试数据,而不必输入数百条记录。
假设我的架构如下所示:
foobar_department_def:
_attributes: { phpName: Department }
id:
name: { type: varchar(64), required: true }
foobar_qualification_def:
_attributes: { phpName: Qualification }
id:
name: { type: varchar(64), required: true }
foobar_employee:
_attributes: { phpName: Employee }
id:
first_name: { type: varchar(64), required: true }
last_name: { type: varchar(64), required: true }
biography: { type: longvarchar, required: false }
qualifi_id: { type: integer, foreignTable: foobar_qualification_def, foreignReference: id, required: true, onUpdate: cascade, onDelete: restrict }
dept_id: { type: integer, foreignTable: foobar_department_def, foreignReference: id, required: true, onUpdate: cascade, onDelete: restrict }
_uniques:
idxu_fb_qly_dept: [qualifi_id, dept_id]
How may I generated test data for jobs (using PHP in my YML file)?。我在 Symfony 文档中看到了这一点 - 然而,尽管再次搜索,我无法在 SF 网站上找到该页面(也许它已被删除?)
I want to generate test data for a fixture file. I wnat to generate the test data instead of having to type in hundreds of records.
Assuming my schema is as shown below:
foobar_department_def:
_attributes: { phpName: Department }
id:
name: { type: varchar(64), required: true }
foobar_qualification_def:
_attributes: { phpName: Qualification }
id:
name: { type: varchar(64), required: true }
foobar_employee:
_attributes: { phpName: Employee }
id:
first_name: { type: varchar(64), required: true }
last_name: { type: varchar(64), required: true }
biography: { type: longvarchar, required: false }
qualifi_id: { type: integer, foreignTable: foobar_qualification_def, foreignReference: id, required: true, onUpdate: cascade, onDelete: restrict }
dept_id: { type: integer, foreignTable: foobar_department_def, foreignReference: id, required: true, onUpdate: cascade, onDelete: restrict }
_uniques:
idxu_fb_qly_dept: [qualifi_id, dept_id]
How may I generate test data for employees (using PHP in my YML file)?. I saw this being done a little while agao, in the Symfony documentation - however, despite searching again, I can't locate the page on the SF website (maybe its been removed?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您正在寻找动态装置。并真正记住这一点:
I guess you are looking for dynamic fixtures. And really keep this in mind:
Symfony 曾经(并且可能仍然)允许在其配置中使用 PHP YML 文件 但我不确定灯具文件。然而,听起来您尝试在 YML 文件中执行 PHP 是没有必要的,您只需要创建一个脚本来写入一个巨大的 YML 文件一次。
要生成固定装置,我建议在您定义的每个表中创建一行,然后将该数据转储到固定装置文件中,为您的数据提供模板。然后将该固定装置模板用于您的 PHP 脚本,用循环中生成的数据替换您的测试值。
Symfony used to (and probably still does) allow PHP in it's configuration YML files but I'm not sure about the fixtures files. However, for what it sounds like you're trying to do PHP in the YML file won't be necessary, you just need to create a script that writes a giant YML file once.
To generate your fixtures I would suggest creating one row in each of the tables you have defined and then dumping that data into a fixtures file to give a template for your data. Then use that fixtures template for your PHP script, replacing your test values with generated data in a loop.