Cucumber:如何在 PHP 中编写片段/步骤定义?

发布于 2024-09-27 19:54:47 字数 475 浏览 0 评论 0原文

我正在尝试让 Cucumber 来测试 PHP 应用程序。到目前为止,我只需在功能目录中运行 cucumber 即可运行该功能。结果的底部写着:

如果您想要不同编程语言的片段,只需确保一个文件 具有适当的文件扩展名的地方存在 Cucumber 查找步骤定义的位置。

这究竟意味着什么?我可以用 Ruby 编写大部分步骤定义,但在某些时候,我需要创建一些设置数据(最好是用 PHP 创建)。如何按照此语句的建议在 PHP 中编写步骤定义?

仅供参考:我对 Ruby 和 Cucumber 也是新手。


解决方案: Cuke4PHP

Cuke4PHP 实现了 Cucumber 线协议,使得用 PHP 编写步骤定义成为可能。

I am trying to get Cucumber working to test a PHP application. So far I am able to get the feature to run by simplying running cucumber in my features directory. At the bottom of the results, it says:

If you want snippets in a different programming language, just make sure a file
with the appropriate file extension exists where cucumber looks for step definitions.

What does this mean exactly? I'm fine with writing most of my step definitions in Ruby, but at some point, I'm going to need to create some setup data (ideally creating it in PHP). How can I write step definitions in PHP as this statement suggests?

FYI: I am new to Ruby and Cucumber as well.


Solution: Cuke4PHP

Cuke4PHP implements the Cucumber wire protocol, making it possible to write step definitions in PHP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

醉城メ夜风 2024-10-04 19:54:47

如果您没有找到解决方案,这就是我今天找到的!这个家伙让我省去了使用 PHP 所必须做的工作哈哈

https://github.com/olbrich/cuke4php

他为 PHP 实现了 wire 协议。简而言之,这是另一台在 Cucumber 发现任何 PHP 步骤时运行 PHP 步骤的服务器。还传回结果。

嗯,不需要再配置 env.rb 了。

If you didn't find a solution, this is what I found today! This guy spared me the work I had to do to use PHP lol

https://github.com/olbrich/cuke4php

He has implemented the wire protocol for PHP. This in a nutshell is another server that runs PHP steps when Cucumber finds any. Also passes back the results.

Ah no need to configure env.rb any more.

挽手叙旧 2024-10-04 19:54:47

看看 Behat,Cucumber 的 PHP 版本:http://everzet.com/Behat/

Have a look at Behat, a PHP version of Cucumber: http://everzet.com/Behat/

烈酒灼喉 2024-10-04 19:54:47

我肚子里有 3 个黄瓜”这样的语句时要做什么:

Given /^I have (\d+) cucumbers in my belly$/ do |cukes|
  # Some Ruby code here
end

步骤定义存储在 features/step_definitions 中,它告诉 Cucumber 在遇到“假设 com/aslakhellesoy/cucumber/wiki/Step-Definitions" rel="nofollow">http://github.com/aslakhellesoy/cucumber/wiki/Step-Definitions

要使用 PHP 编写步骤,只需将它们放入features/step_definitions 并相应地配置您的环境 (features/support/env.rb)。 Cucumber 文档中以 Cucumber 功能的形式提供了很好的信息:

http://github。 com/aslakhellesoy/cucumber/wiki/php

快速 Google 搜索还显示了以下有关使用 Cucumber、Webrat 和 Selenium 进行 PHP 测试的文章,该文章看起来非常有用:

http://dev.af83.com/testing/acceptance-tests-php- project-cucumber-webrat-selenium-trio/2010/06/03

不直接支持的其他语言可以使用 Cucumber 的有线协议,例如 Clucumber (Common Lisp) 所做的:

http://github.com/aslakhellesoy/cucumber/wiki/wire-protocol

我不使用 PHP,但我希望我的回答仍然有帮助。

Step definitions are stored in features/step_definitions and are what tells Cucumber what to do when it encounters statements like "Given I have 3 cucumbers in my belly":

Given /^I have (\d+) cucumbers in my belly$/ do |cukes|
  # Some Ruby code here
end

http://github.com/aslakhellesoy/cucumber/wiki/Step-Definitions

To write your steps in PHP, just put them in features/step_definitions and configure your environment (features/support/env.rb) accordingly. There's good information in the form of a Cucumber feature for this in the Cucumber docs:

http://github.com/aslakhellesoy/cucumber/wiki/php

A quick Google search also brought up the following article on PHP testing with Cucumber, Webrat and Selenium which looks pretty useful:

http://dev.af83.com/testing/acceptance-tests-php-project-cucumber-webrat-selenium-trio/2010/06/03

Other languages that are not directly supported can use Cucumber's wire protocol, which is e.g. what Clucumber (Common Lisp) does:

http://github.com/aslakhellesoy/cucumber/wiki/wire-protocol

I don't do PHP, but I hope my answer still helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文