tags:

views:

67

answers:

1

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.


Update: I am under the impression that I am only able to test PHP applications with Selenium (actual browser). If I am able to test with simulated browsers, or headless browsers, please correct me.

+1  A: 

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.

Michael Kohl
Thanks, but I've already read those articles. The PHP wiki page doesn't talk about how to set up the `support/env.rb` to be able to write step definitions in PHP which is what I am trying to figure out how to do. I haven't been able to find any information on how to write a step definition in a language other than Ruby. Do you know how to do that?
Andrew
The PHP wiki page has an example `environment.rb`, right afer 'And I put the following in "features/support/env.rb"'. Maybe look at Behat, it's a port of Cucumber's language (Gherkin) to PHP: http://everzet.com/Behat/
Michael Kohl
Thanks for the link to Behat. Wasn't aware of a PHP fork of Cucumber. Just wish it didn't require PHP 5.3 to run. =/
Andrew