Laravel behat CSRF 令牌

Laravel behat CSRF token

我正在尝试进行第一个 behat 测试,但是当我 运行 它时,我遇到了 TokenMis... 错误。我知道为什么。因为它没有将 _token 渲染到我的表单中。我检查:

$this->getSession()->getPage()->getHtml()

我得到了:

<input type="hidden" name="_token" value="">

通常必须是:

<input type="hidden" name="_token" value="Atf3lzQ7McA4zQorUu089X3zPsrLVRE8TvQkVOtm">

所以我的问题是我做错了什么?

我的特征看起来:

Feature: User Login
 To test if user can login to system

 Scenario: Successful Authentication
   Given I sign in "email" "pw"
   Then I should be sign in

配置:

default:
  autoload:
    '': %paths.base%/features/bootstrap
  suites:
    default:
      contexts:
        - 'FeatureContext'
      paths:
        - %paths.base%/features/default.feature
    user_login_module:
      contexts:
        - 'UserLoginContext'
      paths:
        - %paths.base%/features/user-login.feature
  extensions:
    Laracasts\Behat:
      env_path: .env.laravel.behat
    Behat\MinkExtension:
      default_session: laravel
      base_url: http://localhost:8080
      laravel: ~

FeatureContext 文件 (UserLoginContext):

<?php

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
use Behat\MinkExtension\Context\MinkContext;
use Laracasts\Behat\Context\Migrator;
use Laracasts\Behat\Context\DatabaseTransactions;
use PHPUnit_Framework_Assert as PHPUnit;

class UserLoginContext extends MinkContext implements Context
{
    use Migrator, DatabaseTransactions;

    /**
     * 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()
    {
    }

    /**
     * Loads Laravel classes
     *
     * @static
     * @beforeSuite
     * @return mixed
     */
    public static function bootstrapLaravel ()
    {
        $app = require __DIR__.'/../../bootstrap/app.php';

        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

        return $app;
    }

    /**
     * @Given I sign in :email :password
     */
    public function iSignIn($email, $password)
    {
        $this->visit('admin-panel');

        $this->fillField('email', $email);
        $this->fillField('password', $password);
        $this->pressButton('Prisijungti');
    }

    /**
     * @Then I should be sign in
     */
    public function iShouldBeSignIn()
    {
        PHPUnit::assertTrue(Auth::guard('admin')->check());

        //$this->assertPageAddress('admin-panel/home');
    }

}

与错误变量相同。抛出错误 undefined errors variable

请将此 CSRF helper function 包含在 blade 文件中。这将自动生成以下代码<input type="hidden" name="_token" value="2WXMw1BMY2o5irBKcXyzJBDeai9colsqFuVpNGXm">

 <form  action = "{{ url('test') }}" method="POST">
 {{ csrf_field() }} 
 ....
 ....
 </form>

编辑 1:

我认为有一个 issue 带有 behat laravel 扩展本身,而不是您的代码。