我有一个项目,我已经在Behat中编写了功能/场景,现在几乎完成了.我必须在网站上测试symfony派上用场的电子邮件功能.但是,我找不到任何帮助我从Behat中配置symfony的教程.大多数网站都提供Symfony中的Behat而不是其他方式.
这篇文章我发现有一些关于配置的信息,但它并不完整.http://extensions.behat.org/symfony2
本文http://docs.behat.org/cookbook/using_the_profiler_with_minkbundle.html 提供了检查电子邮件功能的代码,但没有说明如何在Behat中配置symfony.我安装了symfony扩展.
这是我的composer.json内容:
{
"require": {
"behat/behat": "*",
"behat/mink": "1.4.0",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium-driver": "*",
"behat/mink-selenium2-driver": "*",
"behat/mink-sahi-driver": "*",
"behat/mink-zombie-driver": "*",
"drupal/drupal-extension": "*",
"symfony/process": "*",
"behat/symfony2-extension": "*",
"symfony/form": "*",
"symfony/validator": "*",
"behat/mink-extension": "*",
"symfony/http-kernel": "*",
"fabpot/goutte": "dev-master#5f7fd00"
},
"minimum-stability": "dev",
"config": {
"bin-dir": "bin/"
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以在这里指导我吗?
Fra*_*ula 10
在Symfony 2(.2)配置中,您必须将behat.yml文件放在根文件夹中,因此与composer.json所在的文件夹相同.
app/
bin/
src/
vendor/
web/
behat.yml
composer.json
Run Code Online (Sandbox Code Playgroud)
这是一个工作behat.yml的例子:
default:
# ...
extensions:
Behat\Symfony2Extension\Extension: ~
Behat\MinkExtension\Extension:
goutte: ~
selenium2: ~
Run Code Online (Sandbox Code Playgroud)
现在,您必须启动behat init command
指定所需的Bundle:
php bin/behat @AcmeDemoBundle --init
Run Code Online (Sandbox Code Playgroud)
上面的命令将创建Features
一个包含FeatureContext
类的文件夹.在此类中添加方案的方法.官方hello世界示例下面:
/**
* @Given /^I am in a directory "([^"]*)"$/
*/
public function iAmInADirectory($dir)
{
if (!file_exists($dir))
mkdir($dir);
chdir($dir);
}
/**
* @Given /^I have a file named "([^"]*)"$/
*/
public function iHaveAFileNamed($file)
{
touch($file);
}
/**
* @When /^I run "([^"]*)"$/
*/
public function iRun($command)
{
exec($command, $output);
$this->output = trim(implode("\n", $output));
}
/**
* @Then /^I should get:$/
*/
public function iShouldGet(PyStringNode $string)
{
if ((string) $string !== $this->output)
throw new \Exception("Actual output is:\n" . $this->output);
}
Run Code Online (Sandbox Code Playgroud)
现在,您必须在文件夹中创建要素文件(ls.feature
来自同一示例)Features
:
Feature: ls
In order to see the directory structure
As a UNIX user
I need to be able to list the current directory's contents
Scenario: List 2 files in a directory
Given I am in a directory "test"
And I have a file named "foo"
And I have a file named "bar"
When I run "ls"
Then I should get:
"""
bar
foo
"""
Run Code Online (Sandbox Code Playgroud)
因此,您的Features
文件夹将如下所示:
Acme\DemoBundle\Features
|- Context /
|- FeatureContext.php
ls.feature
Run Code Online (Sandbox Code Playgroud)
最后,推出behat并享受!
php bin/behat @AcmeDemoBundle
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3473 次 |
最近记录: |