ingenerator / be_entity
该软件包已被废弃,不再维护。未建议替代软件包。
Behat 的 Doctrine 2 实体工厂和预期测试辅助框架
v1.0.0
2019-04-03 14:01 UTC
Requires
- php: ^7.2
- behat/behat: ^2.4
- doctrine/orm: ^2.3
Requires (Dev)
- phpspec/phpspec: ^2.0
This package is auto-updated.
Last update: 2022-02-01 12:26:39 UTC
README
通过在功能文件中轻松指定 Doctrine2 实体,而不是在单独的固定文件中,来提高 Behat 套件的可读性。
使用示例
Given a User entity "ingenerator@users.noreply.github.com" with password "12345678" And I go to "/login" And I fill in "email" with "ingenerator@users.noreply.github.com" And I fill in "password" with "12345678" When I press "Login" Then I should be on "/" And I should be logged in Given no User entity "nobody.here@no.domain" And I go to "/login" And I fill in "email" with "ingenerator@users.noreply.github.com" And I fill in "password" with "12345678" When I press "Login" Then I should be on "/login" And I should see "Invalid user or password"
namespace Ingenerator\BeEntity\Factory; class User extends Ingenerator\BeEntity\Factory { protected function _locate($identifier) { return $this->entity_manager->getRepository('Project\User')->findOneBy(array('email' => $identifier)); } protected function _create($identifier) { $user = new Project\User; $user->set_email($identifier); $user->set_password('foo'); return $user; } }
安装
添加到您的 composer.json 文件中
{ "require": { "ingenerator/be_entity" : "dev-master" } }
将 BeEntity 上下文创建为 FeatureContext 的子上下文
class FeatureContext extends Behat\Behat\Context\BehatContext { public function __construct() { $em = new Doctrine\ORM\EntityManager; // Whatever code you need to get an EntityManager instance in your app $this->useContext('be_entity', new Ingenerator\BeEntity\Context\BeEntityContext($em)); } }
为要在功能中使用的每种实体类型创建工厂类 - 请参阅上面的示例 User 工厂。您的工厂定义了如何使用步骤参数来搜索该类型的实体,并为新的实体记录声明合理的默认值。
请注意,您可以为应用程序中的每种实体类型拥有多个工厂类 - 例如,您可能会创建一个 Administrator 工厂,该工厂创建具有特定字段集或分配特定角色的 Project\User 实体。
路线图
- 实体序列的生成器 - 例如 user1, user2, user3
- 实体引用 - 例如
Given the Blog entity "My first blog" has author "User: ingenerator@users.noreply.github.com"
- 针对需要空数据库或集成构建的特定场景的 db/wipe table 插件
- 审查实体管理器的注入,并考虑服务容器层
贡献者和信用
- Andrew Coulton acoulton [主要开发者]
深受thoughtbot 的 factory_girl ruby gem的启发。