简体   繁体   English

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

[英]Cucumber: How to write snippets/step definitions in PHP?

I am trying to get Cucumber working to test a PHP application. 我试图让Cucumber正在测试PHP应用程序。 So far I am able to get the feature to run by simplying running cucumber in my features directory. 到目前为止,我能够通过在我的功能目录中简化运行cucumber来运行该功能。 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). 我在Ruby中编写大部分步骤定义时很好,但在某些时候,我需要创建一些设置数据(理想情况下是在PHP中创建它)。 How can I write step definitions in PHP as this statement suggests? 如此语句建议,如何在PHP中编写步骤定义?

FYI: I am new to Ruby and Cucumber as well. 仅供参考:我也是Ruby和Cucumber的新手。


Solution: Cuke4PHP 解决方案: Cuke4PHP

Cuke4PHP implements the Cucumber wire protocol, making it possible to write step definitions in PHP. Cuke4PHP实现了Cucumber有线协议,可以在PHP中编写步骤定义。

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

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 这家伙省去了我必须要做的工作才能使用PHP lol

https://github.com/olbrich/cuke4php https://github.com/olbrich/cuke4php

He has implemented the wire protocol for PHP. 他已经实现了PHP的有线协议 This in a nutshell is another server that runs PHP steps when Cucumber finds any. 简而言之,这是另一台运行PHP步骤的服务器,当Cucumber找到它时。 Also passes back the results. 还传回结果。

Ah no need to configure env.rb any more. 啊不需要再配置env.rb了。

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": 步骤定义存储在features/step_definitions ,并告诉Cucumber在遇到“我肚子里有3个黄瓜”等语句时该怎么做:

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

http://github.com/aslakhellesoy/cucumber/wiki/Step-Definitions 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. 要在PHP中编写步骤,只需将它们放在features/step_definitions并相应地配置您的环境( features/support/env.rb )。 There's good information in the form of a Cucumber feature for this in the Cucumber docs: 在Cucumber文档中有一个黄瓜功能形式的良好信息:

http://github.com/aslakhellesoy/cucumber/wiki/php 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: 快速谷歌搜索还提出了以下关于使用Cucumber,Webrat和Selenium进行PHP测试的文章,它看起来非常有用:

http://dev.af83.com/testing/acceptance-tests-php-project-cucumber-webrat-selenium-trio/2010/06/03 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 eg what Clucumber (Common Lisp) does: 其他不直接支持的语言可以使用Cucumber的有线协议,例如Clucumber(Common Lisp)所做的事情:

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

I don't do PHP, but I hope my answer still helps. 我不做PHP,但我希望我的回答仍然有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM