开发者

Cucumber: How to write snippets/step definitions in 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 d开发者_开发技巧ata (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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜