2017-03-03 4 views
0

에 로그인되어 있는지 확인하고 나는 사용자가 로그인 한 경우 다음과 같이 확인하기 위해 컨텍스트를 만들려면 :Behat/심포니 3 - 사용자가 내가 behat와 심포니 3을 사용하고

public function __construct(
     UserManagerInterface $userManager, 
     AuthorizationCheckerInterface $authorizationChecker, 
     TokenStorageInterface $tokenStorage 
    ) { 
     $this->userManager = $userManager; 
     $this->authorizationChecker = $authorizationChecker; 
     $this->tokenStorage = $tokenStorage; 
    } 

/** 
    * @param string $user 
    * @param string $role 
    * 
    * @Then /^I should be login as "([^"]*)" with the role "([^"]*)"$/ 
    */ 
    public function iShouldBeLoggedInAsWithTheRole(string $user, string $role): void 
    { 
     $loggedUser = $this->tokenStorage->getToken()->getUsername(); 
     var_dump($loggedUser); 

     Assert::same(
      $loggedUser, 
      $user, 
      "The logged user is $loggedUser, expected $user" 
     ); 

     Assert::true(
      $this->authorizationChecker->isGranted($role), 
      "The user $user must have the role $role" 
     ); 
    } 

그리고 이것은 단계들입니다. 첫 번째 오류는 컨텍스트에서 정의한 단계를 실행하면서 실패합니다. 두 번째 작업은 사용자 프로필 페이지로 이동하여 사용자의 전자 메일이 페이지에 있는지 확인합니다. 로그인이 올바르게 완료된 경우에만 발생할 수 있습니다. 문제는 사용자 컨텍스트의 토큰 저장소 인 것 같습니다. 어떤 이유입니까?

Scenario: Log in with username and password 
    Given I am on "/login" 
    When I fill in the following: 
     | username | [email protected] | 
     | password | 1234    | 
    And I press "_submit" 
    And I am on "/" 
    Then I should be login as "[email protected]" with the role "ROLE_USER" 
     The logged user is anon., expected [email protected] (InvalidArgumentException) 

    Scenario: Log in with username and password 
    Given I am on "/login" 
    When I fill in the following: 
     | username | [email protected] | 
     | password | 1234    | 
    And I press "_submit" 
    And I am on "/profile" 
    Then I should see "[email protected]" 

그리고 이것은 당신은 프로세스 당신이있어 behat 과정의 완전히 독립적 인 "시뮬레이션 브라우저 페이지"

Given I am on "/login" 
    When I fill in the following: 
    | username | [email protected] | 
    | password | 1234    | 
    And I press "_submit" 

을 통해 로그인하는 behat 구성

default: 
    formatters: 
     pretty: 
      verbose: true 
      paths: false 
      snippets: false 

    extensions: 

     Behat\MinkExtension: 
       base_url: 'https://localhost/app_dev.php/' 
       sessions: 
        default: 
         symfony2: ~ 

     Behat\Symfony2Extension: 
      kernel: 
       env: test 
       debug: true 

     FriendsOfBehat\CrossContainerExtension: ~ 

     FriendsOfBehat\PerformanceExtension: ~ 

     FriendsOfBehat\VariadicExtension: ~ 

    gherkin: 
     filters: 
      tags: "[email protected] && [email protected]" # CLI is excluded as it registers an error handler that mutes fatal errors 
+0

은 WebDriver가 설치된 UI 또는 셀레늄 등과 관련된 시나리오입니까? 또는 "브라우저"기능없이 실행 중입니까? – DonCallisto

+0

@DonCallisto 브라우저 기능이 없으면 질문에 behat 설정을 추가했습니다. – petekaner

답변

0

입니다 로그 된 사용자를 검색하려고합니다.

당신이 할 수있는 유일한 일은 shared context 종류의이 사용자를 저장하고 로그인 단계를 다시 정의하고,이 사용자를 확인한 다음에 확인하는 것입니다 (하지만 그 시점에서이 테스트는 꽤 쓸모없는 것처럼 보입니다)