rezzza/rest-api-behat-extension
最新稳定版本:v3.0.1
Composer 安装命令:
composer require rezzza/rest-api-behat-extension
包简介
Alice extension for Behat
README 文档
README
You can import fixtures through a yaml file and from a behat step.
Versions
Installation
Through Composer :
$ composer require --dev "rezzza/alice-extension:1.0.*@dev"
Configure your behat.yml :
default: extensions: Rezzza\AliceExtension\Extension: fixtures: /path/to/your/fixtures.yml lifetime: (scenario|feature) faker: locale: en_US #default providers: []
To write your fixtures.yml please report to Alice documentation
This extension need Symfony2Extension to work. Have a look to its documentation
Usage
In your behat configuration you can activate AliceContext for the test suite you need
default: suites: default: contexts: - Rezzza\AliceExtension\Context\AliceContext
So you can now write in your features :
Feature: Test My feature Background: Write fixtures Given I load "Vendor\My\Entity" fixtures where column "key" is the key: | key | id | name | | fixture1 | 1 | jean | | fixture2 | 2 | marc |
If you use yaml file, you should consider put your default values in it thanks to template inheritance.
And use inline fixtures to override values you need.
Hook for specific entities
Sometimes you need to apply specific operations for objects persisted. You can do it through the Symfony2 Bundle packed with this extension.
Activate the bundle:
<?php /***/ class AppKernel extends Kernel { public function registerBundles() { $bundles = array( /***/ new Rezzza\AliceExtension\Symfony\Bundle\RezzzaAliceExtensionBundle() /***/ ); } } ?>
Then in your Symfony2 app you will be able to build some Alice processors via service. It should extends Nelmio\Alice\ProcessorInterface and registred via the tag alice_extension.processor
Adapters
Currently we support :
- DoctrineORM
- ElasticSearch (through FOSElasticaBundle)
default: extensions: Rezzza\AliceExtension\Extension: adapters: elastica: ~ orm: ~
For ElasticSearch we should use mapping config to indicate which ElasticSearch type alice should use to persist your mode:
default: extensions: Rezzza\AliceExtension\Extension: adapters: elastica: index_service: fos_elastica.index.name_of_your_index mapping: myType: My\Fully\Model orm: ~
Then in your features you should use tag to specify which adapters alice should use :
@alice:elastica Feature: Test My feature Background: Write fixtures Given I load "Vendor\My\Entity" fixtures where column "key" is the key: | key | id | name | | fixture1 | 1 | jean | | fixture2 | 2 | marc |
Advanced Fixtures
Fixtures can be managed through the configuration.
default: extensions: Rezzza\AliceExtension\Extension: default_loading: implicit fixtures: default: [users, products] # could be scalar if you want only one => users key_paths: users: /src/path/to/your/fixtures.yml products: /src/path/to/your/fixtures.yml
With this kind of configuration, when you'll call step below, it'll load default fixtures (users and products in this example).
default_loading key is important here, if it's defined as implicit, it'll implicitly load default fixtures when you use step below. If it's defined as explicit you'll have to use Given I load "default" fixtures to load default fixtures.
Given I load "Acme\Bundle\Entity\User" fixtures where column "key" is the key:
| key | emailAddress | password |
| user1 (extends user) | chuck@norris.com | password |
You are able to load fixtures manually:
Given I load "default" fixtures # will load users AND products
Given I load "users" fixtures # will load users
Given I load "products" fixtures # will load products
Of course, fixtures are loaded once.
Faker Providers
Some providers are available on AliceExtension:
- NullProvider:
<null> - FixedDateTimeProvider:
<fixedDateTime("+1 hour")>
You can add them (or your own) easily in behat.yml configuration:
default: extensions: Rezzza\AliceExtension\Extension: ..... faker: locale: en_US #default providers: - \Rezzza\AliceExtension\Providers\NullProvider - \Rezzza\AliceExtension\Providers\FixedDateTimeProvider - \Acme\Providers\YourOwnProvider
Lifetime
2 lifetime options are available.
- scenario : will reset fixtures after each scenario. You have to use background step to describe your fixtures
- feature : will reset fixtures after each feature. You have to use scenario step to describe your fixtures
FAQ
-
I want to use this with Doctrine ODM !
-
You should do a PR
-
I wanto to use this with PostgreSQL !
-
You should do a PR
rezzza/rest-api-behat-extension 适用场景与选型建议
rezzza/rest-api-behat-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 85.1k 次下载、GitHub Stars 达 34, 最近一次更新时间为 2015 年 04 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「fixtures」 「BDD」 「alice」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 rezzza/rest-api-behat-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rezzza/rest-api-behat-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 rezzza/rest-api-behat-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Helper that decorates any SUS with a phpspec lazy object wrapper
Behat Context for testing Symfony Api
Provides access to magento2 object manager from behat and allows to change magento config settings temporarly
Testing object factory for PHP
Testing object factory for PHP
The bundle for easy using json-rpc api on your project
统计信息
- 总下载量: 85.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 34
- 点击次数: 14
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-20