我正在使用 Laravel 5 Behat Mink Extension for Laravel 。用于安装组件的 composer.json 片段是:

"require-dev": {
    "phpunit/phpunit": "~4.0",
    "behat/behat": "^3.0",
    "behat/mink": "^1.6",
    "behat/mink-extension": "^2.0",
    "laracasts/behat-laravel-extension": "^1.0"
}

我已经在 behat.yml 中设置了基本 URL,文件的全部内容:
default:
    extensions:
        Laracasts\Behat:
            # env_path: .env.behat
        Behat\MinkExtension:
            base_url: http://localhost/leaveTracker/public
            default_session: laravel
            laravel: ~

请注意,我在这里将 base_url 设置为:
            base_url: http://localhost/leaveTracker/public

我还编写了这个示例功能:
Feature: Viewing the list of employees
In order to operate the employees' data
As a user
I need to see the list of employees

Scenario: I have the option to add employee
    Given I am on page "/employee"
    Then the current URL should be "http://localhost/leaveTracker/public/employee"
FeatureContext.php 的相应部分是:
/**
 * @Then the current URL should be :arg1
 */
public function theCurrentUrlShouldBe($arg1)
{
    PHPUnit::fail($this->getSession()->getCurrentUrl());
}

在这里,我收到以下对我来说很正常的错误:
Scenario: I have the option to add employee
Given I am on page "/employee"
Then the current URL should be "http://localhost/leaveTracker/public/employee"
    Failed asserting that two strings are equal.
    --- Expected
    +++ Actual
    @@ @@
    -'http://localhost/employee'
    +'http://localhost/leaveTracker/public/employee'

所以现在我的问题是: 为什么 base_url 不是从 behat.yml 文件中读取的?

注意: 我也尝试设置 base_url: https://test.com ,但它需要 http://localhost/employee

最佳答案

从 Behat 2.x 更新到 Behat 3.x 时,我遇到了同样的问题

behat.yml: [定义 base_url]

extensions:
    Behat\MinkExtension:
        base_url: 'http://localhost/index.php'

在从 RawMinkContext 调用扩展的 Context 类中:
$this->visitPath($url);

该函数结合了 $config['base_url']$url 。调用 $this->getSession()->visit($url) 浏览到普通的 $url

关于php - Laravel 5、Behat、Mink : base_url parameter is not read from behat. yml,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30423211/

10-13 21:36