是不认识一些小黄瓜行
behat not recognising some gherkin rows
我正在尝试 运行 behat,我制作了一个场景大纲,但是跳过了一些带有参数的行并且一些变量被错误地使用了。
这是写在 .feature 上的小黄瓜场景大纲,其中包含已分配的功能:
Scenario Outline: CreatePostUseCase service # tests/integration/BlogApp/Feature/BlogApp.feature:7
Given an <userid> # IntegrationTests\BlogApp\Context\BlogAppContext::aUserId()
And an <email> // <- email row is skipped and no anEmail() function assigned
And a <password> # IntegrationTests\BlogApp\Context\BlogAppContext::aTitle() // <- why is assigning aTitle() in password?
When creating and saving a User object # IntegrationTests\BlogApp\Context\BlogAppContext::creatingAndSavingAUserObject()
Given a <title> // <- why is not assigning aTitle() here?
And a <body> // <- this one is also skipped
When creating a Post object # IntegrationTests\BlogApp\Context\BlogAppContext::creatingAPostObject()
Given a <publish> param # IntegrationTests\BlogApp\Context\BlogAppContext::aPublish()
And persist the Post // <- this one is also skipped
Then an event should be launched # IntegrationTests\BlogApp\Context\BlogAppContext::anEventShouldBeLaunched()
这是上下文:
/**
* @Given an :userid
*/
public function aUserId($userId)
{
$this->userId = $userId;
}
/**
* @And an :email
*/
public function anEmail($email)
{
$this->email = new Email($email);
}
/**
* @And a :password
*/
public function aPassword($password)
{
$this->password = new Password($password);
}
/**
* @When creating and saving a User object
*/
public function creatingAndSavingAUserObject()
{
$this->user = new User($this->userId, $this->email, $this->password);
$this->userRepository = new UserRepository();
$this->userRepository->save($this->user);
}
/**
* @Given a :title
*/
public function aTitle($title)
{
$this->title = $title;
}
/**
* @And a :body
*/
public function aBody($body)
{
$this->body = $body;
}
/**
* @When creating a Post object
*/
public function creatingAPostObject()
{
$this->user = new Post($this->title, $this->body);
}
/**
* @Given a :publish param
*/
public function aPublishParam($publish)
{
$this->publish = $publish;
}
/**
* @And persist the Post
*/
public function persistThePost()
{
$this->postRepository = new PostRepository();
$this->eventQueue = new EventQueue();
$this->createPostUseCase = new CreatePostUseCase($this->postRepository, $this->userRepository, $this->eventQueue);
$this->createPostUseCase->execute($this->user, $this->post, $this->publish);
}
/**
* @Then an event should be launched
*/
public function anEventShouldBeLaunched()
{
$lastEvent = $this->eventQueue->getLastEvent();
$event = $lastEvent->getPost();
PHPUnit_Framework_Assert::assertEquals($event->getTitle(), $this->event->getTitle());
}
这些是来自 .feature
的示例
Examples:
| userid | email | password | title | body | publish |
| 1 | test@email.com | abcd1234 | foo bar | lorem ipsum dolor sit amet textae lungum is dolorem fistrum et duodenum pecatorum | NULL |
| 2 | fake@email.com | password123 | baz geek | lorem ipsum dolor sit amet textae lungum is dolorem fistrum et duodenum | true |
我的代码有问题,但我看不出它有什么问题或哪里有问题。有人可以帮我知道为什么要跳过一些参数吗?
让它们与众不同的是 Gherkin 语法,在您的情况下:
@And a :password
与@Given a :title
相同,与@And an :email
相同,因为:password
等只是一些标签,不属于步骤的一部分。
Behat 认为的步骤是:a <parameter>
添加其他不同的词,例如:@Given a title :title
、@And a password :password
、@And an email :email
Better, I recommend reading about best practices for BDD. Avoid using steps just to set a parameter, use the parameter to generate a set of values in an array or in any way you need them.
我正在尝试 运行 behat,我制作了一个场景大纲,但是跳过了一些带有参数的行并且一些变量被错误地使用了。
这是写在 .feature 上的小黄瓜场景大纲,其中包含已分配的功能:
Scenario Outline: CreatePostUseCase service # tests/integration/BlogApp/Feature/BlogApp.feature:7
Given an <userid> # IntegrationTests\BlogApp\Context\BlogAppContext::aUserId()
And an <email> // <- email row is skipped and no anEmail() function assigned
And a <password> # IntegrationTests\BlogApp\Context\BlogAppContext::aTitle() // <- why is assigning aTitle() in password?
When creating and saving a User object # IntegrationTests\BlogApp\Context\BlogAppContext::creatingAndSavingAUserObject()
Given a <title> // <- why is not assigning aTitle() here?
And a <body> // <- this one is also skipped
When creating a Post object # IntegrationTests\BlogApp\Context\BlogAppContext::creatingAPostObject()
Given a <publish> param # IntegrationTests\BlogApp\Context\BlogAppContext::aPublish()
And persist the Post // <- this one is also skipped
Then an event should be launched # IntegrationTests\BlogApp\Context\BlogAppContext::anEventShouldBeLaunched()
这是上下文:
/**
* @Given an :userid
*/
public function aUserId($userId)
{
$this->userId = $userId;
}
/**
* @And an :email
*/
public function anEmail($email)
{
$this->email = new Email($email);
}
/**
* @And a :password
*/
public function aPassword($password)
{
$this->password = new Password($password);
}
/**
* @When creating and saving a User object
*/
public function creatingAndSavingAUserObject()
{
$this->user = new User($this->userId, $this->email, $this->password);
$this->userRepository = new UserRepository();
$this->userRepository->save($this->user);
}
/**
* @Given a :title
*/
public function aTitle($title)
{
$this->title = $title;
}
/**
* @And a :body
*/
public function aBody($body)
{
$this->body = $body;
}
/**
* @When creating a Post object
*/
public function creatingAPostObject()
{
$this->user = new Post($this->title, $this->body);
}
/**
* @Given a :publish param
*/
public function aPublishParam($publish)
{
$this->publish = $publish;
}
/**
* @And persist the Post
*/
public function persistThePost()
{
$this->postRepository = new PostRepository();
$this->eventQueue = new EventQueue();
$this->createPostUseCase = new CreatePostUseCase($this->postRepository, $this->userRepository, $this->eventQueue);
$this->createPostUseCase->execute($this->user, $this->post, $this->publish);
}
/**
* @Then an event should be launched
*/
public function anEventShouldBeLaunched()
{
$lastEvent = $this->eventQueue->getLastEvent();
$event = $lastEvent->getPost();
PHPUnit_Framework_Assert::assertEquals($event->getTitle(), $this->event->getTitle());
}
这些是来自 .feature
的示例Examples:
| userid | email | password | title | body | publish |
| 1 | test@email.com | abcd1234 | foo bar | lorem ipsum dolor sit amet textae lungum is dolorem fistrum et duodenum pecatorum | NULL |
| 2 | fake@email.com | password123 | baz geek | lorem ipsum dolor sit amet textae lungum is dolorem fistrum et duodenum | true |
我的代码有问题,但我看不出它有什么问题或哪里有问题。有人可以帮我知道为什么要跳过一些参数吗?
让它们与众不同的是 Gherkin 语法,在您的情况下:
@And a :password
与@Given a :title
相同,与@And an :email
相同,因为:password
等只是一些标签,不属于步骤的一部分。
Behat 认为的步骤是:a <parameter>
添加其他不同的词,例如:@Given a title :title
、@And a password :password
、@And an email :email
Better, I recommend reading about best practices for BDD. Avoid using steps just to set a parameter, use the parameter to generate a set of values in an array or in any way you need them.