Behat-passing parameters to mink-extension

1k Views Asked by At

I'm making a Behat testing of all pages on my application. like:

 Feature: Login
    In order to see if the Login works
  As a website user
  I need to be able to see the Login page

  Scenario: See the login page
    Given I am on "/"
    Then I should see "Welcome"

The problem I'm facing is the /people page has a twig filter, so the test:

    Feature: People
  In order to see if the people works
  As a website user
  I need to be able to see the People page

  Scenario: See the people page
    Given I am on "/user-list"
    Then I should see "People"

Is failing:

Given I am on "/user-list" # Behat\MinkExtension\Context\MinkContext::visit() Type error: Argument 1 passed to myMelomanBundle\TwigFilters\FollowingFilter::followingFilter() must be of the type integer, null given, called in vendor/twig/twig/lib/Twig/Environment.php(373) : eval()'d code on line 168 (Behat\Testwork\Call\Exception\FatalThrowableError)

Should I Create a PeopleContext.php to pass a parameter to this twig filter? Or theres is a way to pass it directly with Mink (behat.yml)?

Behat.yml

 default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Behat\MinkExtension\Context\MinkContext
        - LikesContext
        - ParametersContext
  extensions:
      Behat\Symfony2Extension: ~
      Behat\MinkExtension:
          base_url: 'http://melomaniacs.com/app_dev.php/'
          sessions:
              default:
                  symfony2: ~

FollowingFilter on the view: (me is int and user is User Object), and it check if the current user is following to each user.

<button class="btn btn-md btn-success btn-follow
     {% if me|following(user) %} // Here
         hidden
        {% endif %}
     "
    data-follow="{{ user.id }}
    onclick="followAjax.followRequest(this)">
    <span class="fa fa-user-plus" aria-hidden="true"></span>
    Follow
</button>

FollowingFilter.php sample:

 public function followingFilter(int $userId, User $friend)
{
    $user = $this->userRepository->findOneBy(
        array(
            'id' => $userId
        )
    );

    $following = $this->followingRepository->findOneBy(
        array(
            'user' => $user,
            'friend'=> $friend
        )
    );

    if (!empty($following) && is_object($following)) {
        return true;
    } else return false;

}
0

There are 0 best solutions below