Php Behat将参数传递给mink扩展
我正在对应用程序上的所有页面进行行为测试。比如:Php Behat将参数传递给mink扩展,php,symfony,behat,mink,Php,Symfony,Behat,Mink,我正在对应用程序上的所有页面进行行为测试。比如: 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" 我面临的问题是/people页面有一个细枝
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"
我面临的问题是/people页面有一个细枝过滤器,因此测试:
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"
正在失败:
假设我在“/用户列表”上#Behat\MinkExtension\Context\MinkContext::visit()
类型错误:传递给myMelomanBundle\TwigFilters\FollowFilter::FollowFilter()的参数1必须是整数类型,给定为null,在第168行的vendor/twig/twig/twig/lib/twig/Environment.php(373):eval()代码中调用(Behat\Testwork\Call\Exception\FatalThrowableError)
我应该创建一个PeopleContext.php来向这个细枝过滤器传递一个参数吗?或者有没有一种方法可以让水貂直接通过它(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: ~
视图上的followFilter:(me是int,user是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>
这是整个yml文件吗?你能从水貂身上取些什么吗?您正在使用Pare对象吗?请参见此处的
上下文参数
是的,这是整个文件。我没有凌驾于水貂之上。如果有办法,我想知道如何将Id传递给下面的过滤器。你的意思是我应该创造一个新的环境?。谢谢,我不知道什么是myMelomanBundle\TwigFilters\followFilter::followFilter()
以及它是如何调用的。现在我知道followFilter
的样子,但不知道我在“/用户列表”上的情况
id触发它,或者如果您以某种方式这样做,或者您需要通过这些参数,或者需要从某个地方读取这些参数。我只想要可以访问/user list的测试。此页面有一个twigFilter,它从twig变量接收2个参数。我不知道如何在我的测试中避免这个错误。这是整个yml文件吗?你能从水貂身上取些什么吗?您正在使用Pare对象吗?请参见此处的上下文参数
是的,这是整个文件。我没有凌驾于水貂之上。如果有办法,我想知道如何将Id传递给下面的过滤器。你的意思是我应该创造一个新的环境?。谢谢,我不知道什么是myMelomanBundle\TwigFilters\followFilter::followFilter()
以及它是如何调用的。现在我知道followFilter
的样子,但不知道我在“/用户列表”上的情况
id触发它,或者如果您以某种方式这样做,或者您需要通过这些参数,或者需要从某个地方读取这些参数。我只想要可以访问/user list的测试。此页面有一个twigFilter,它从twig变量接收2个参数。我不知道如何避免考试中的那个错误。
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;
}