cevinio/behat-laravel-extension
Composer 安装命令:
composer require cevinio/behat-laravel-extension
包简介
Laravel extension for Behat
关键字:
README 文档
README
This extension offers an incredibly simple (and fast) way to begin testing and driving your Laravel applications with Behat. Some benefits include:
- Fast: It doesn't depend on anything like Goutte, so it offers a super-fast way to test your UI. You don't even need to setup a host to run your tests.
- Refresh: Laravel is automatically rebooted before each scenario (so nothing like user sessions will be persisted).
- Environments: Specifying custom environment files (like the
.envone) for different app environments is a little tricky in Laravel. This extension handles that for you automatically. - Access Laravel: You instantly have access to Laravel (things like facades and such) from your
FeatureContextfile.
This repository is forked from laracasts/Behat-Laravel-Extension because it was no longer being maintained.
Credits go to Jeffrey Way for originally creating this extension.
1. Install
Require the package as a dev dependency via Composer.
composer require --dev cevinio/behat-laravel-extension
This will also pull in Behat and Mink.
2. Create the Behat.yml Configuration File
Next, within your project root, create a behat.yml file, and add:
default:
extensions:
Cevinio\Behat:
# bootstrap_path: ~
# env_path: ~
Behat\MinkExtension:
default_session: laravel
laravel: ~
files_path: "%paths.base%/tests/"
Here, is where we reference the Laravel extension, and tell Behat to use it as our default session.
You may pass an optional parameter, env_path (currently commented out above) to specify the name of the environment file that should be referenced from your tests.
The default is empty and will keep Laravel standard behavior to look for .env. If you want a special environment file you can set it for example to .env.behat. This file should, like the standard .env file in your project root, contain any special environment variables for your tests (such as a special acceptance test-specific database).
It is also possible to specify an alternative bootstrap file by setting the optional parameter bootstrap_path (this defaults to bootstrap/app.php). Behat's %paths.base% will always be prepended to this path.
3. Setting up FeatureContext
Run, from the root of your app
vendor/bin/behat --init
It should set
features/bootstrap/FeatureContext.php
At this point you should set it to extend MinkContext and implement LaravelAwareContext.
You can use the LaravelAware trait to get access to the Application via $this->app().
<?php
use Behat\Behat\EventDispatcher\Event\BeforeScenarioTested;
use Behat\MinkExtension\Context\MinkContext;
use Cevinio\Behat\Context\LaravelAware;
use Cevinio\Behat\Context\LaravelAwareContext;
use Illuminate\Contracts\Foundation\Application;
/**
* Defines application features from the specific context.
*/
class FeatureContext extends MinkContext implements LaravelAwareContext
{
use LaravelAware;
public function bootstrapLaravelEnvironment(BeforeScenarioTested $event): array
{
// This method is optional, if implemented the returned array is set in the Laravel environment for access via env().
// This allows modification of configuration values on a per-scenario basis.
}
public function bootstrapLaravelApplication(Application $app, BeforeScenarioTested $event): void
{
// This method is optional. It allows access to the Application right after it was created.
// This allows for example to call $app->bind() before any @BeforeScenario hook is called.
}
}
4. Write Some Features
You're all set to go! Start writing some features.
Note: if you want to leverage some of the Mink helpers in your
FeatureContextfile, then be sure to extendBehat\MinkExtension\Context\MinkContext.
cevinio/behat-laravel-extension 适用场景与选型建议
cevinio/behat-laravel-extension 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 80.88k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2021 年 03 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「BDD」 「Behat」 「extension」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 cevinio/behat-laravel-extension 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 cevinio/behat-laravel-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 cevinio/behat-laravel-extension 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Helper that decorates any SUS with a phpspec lazy object wrapper
Behat Context for testing Symfony Api
A Behat Extension that allows custom bootstrapping
Environment processor and contexts autoloader
Provides access to magento2 object manager from behat and allows to change magento config settings temporarly
A custom URL rule class for Yii 2 which allows to create translated URL rules
统计信息
- 总下载量: 80.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-03-15