Behat test"然后我应该看到Laravel 5"在laravel应用程序中失败

时间:2016-07-02 02:54:07

标签: php laravel laravel-5 bdd behat

我有一台带有El El Capitan的Macbook。在我的新Laravel应用程序中(由 $ composer create-project laravel/laravel my_app),我输入:

$ php artisan serve

在localhost:8000上的浏览器(Safari或Chrome)中,我成功地看到了黑色文字" Laravel 5"在网页上。

我在feature /中有一个hometest.feature文件,如下所示:

Feature:
  In order to prove that Behat works as intended
  We want to test the home page for a phrase
  Scenario: Root Test
    When I am on the homepage
    Then I should see "Laravel 5"

我有一个/features/bootstrap/FeaturesContext.php文件,如下所示:

<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

/**
 * Defines application features from the specific context.
 */
class FeatureContext extends Behat\MinkExtension\Context\MinkContext implements Context, SnippetAcceptingContext
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {
    }
}

我有一个behat.yml文件,如下所示:

default:
    extensions:
        Laracasts\Behat:
            # env_path: .env.behat
        Behat\MinkExtension:
            default_session: laravel
            base_url: http://localhost:8000
            laravel: ~

当我运行时(localhost正在运行或未运行=不会导致结果不同):

$ vendor/bin/behat

控制台输出是:

Feature:
  In order to prove that Behat works as intended
  We want to test the home page for a phrase

  Scenario: Root Test             # features/hometest.feature:5
    When I am on the homepage     # FeatureContext::iAmOnHomepage()
    Then I should see "Laravel 5" # FeatureContext::assertPageContainsText()
      The text "Laravel 5" was not found anywhere in the text of the current page. (Behat\Mink\Exception\ResponseTextException)

--- Failed scenarios:

    features/hometest.feature:5

1 scenario (1 failed)
2 steps (1 passed, 1 failed)
0m0.12s (20.26Mb)

为什么我的简单&#34;我应该看到Laravel 5&#39;测试失败?如果localhost需要运行,我该如何同时运行我的测试?当我启动本地主机时,我在终端中输入的任何内容都不再收到响应。

我的适用文件夹的目录结构:

app/
bootstrap/
...
features/
    bootstrap/
        FeatureContext.php
    hometest.feature
...
.env.behat
behat.yml
composer.json
...
etc.

谢谢!

2 个答案:

答案 0 :(得分:8)

Finally! I found via my server logs (storage/logs/laravel.log) that the page rendered contained the text "Whoops, looks like something went wrong." (obviously the wrong page). The error was "development.ERROR: exception 'RuntimeException' with message 'No supported encrypter found. The cipher and / or key length are invalid.'" There are about 50 questions and answers on StackOverflow for this, and none of them worked. After researching for days, finally I found my solution. It may be a combination of previous changes I had made, or the success could entirely be due to this command. In any case, try:

php artisan config:cache

Phew!

答案 1 :(得分:0)

我通过在env.behat文件中添加APP_KEY来解决这个问题