承接 cevinio/behat-laravel-extension 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 .env one) 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 FeatureContext file.

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 FeatureContext file, then be sure to extend Behat\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 我们能提供哪些服务?
定制开发 / 二次开发

基于 cevinio/behat-laravel-extension 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 80.88k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-15