3

How can I manualy make sure that user is not logged in my FeatureContext class in BDD Behat scenario? For example I have this scenario:

Scenario: passing wrong values will not get me in
Given I am on "/login"
And I am not logged in
When I fill in "login" with "KtokolwiekWidzialKtokolwiekWie"
When I fill in "password" with "root_as_allways"
When I press "Login"
Then I should be on "/"
And I should see "Wrong login or password"

And I've defined this context:

/**
 * @Given /^I am not logged in$/
 */
public function iAmNotLoggedIn()
{
    # logout currently login user, if any
    $request = $this->kernel->getContainer()->get('request');
    $request->getSession()->invalidate();
}

But this gives me an error when running this feature test.

You cannot create a service ("request") of an inactive scope ("request").

Note: I'm using Symfony 2.1 RC-1

4

2 に答える 2

4

Here's the custom step you can use:

/**
 * @Given /^I am not logged in$/
 */
public function iAmNotLoggedIn()
{
    $this->getMink()
        ->getSession()
        ->visit($this->locatePath('/logout'))
    ;
}

But you probably need to update your steps order:

Given I am not logged in
  And I am on "/login"
于 2012-08-22T17:37:03.237 に答える
2

「/logout」にアクセスするだけで、ログアウトされます。「/login」に移動する前にこれを行ってください

于 2012-08-22T17:00:08.140 に答える