Cucumber for PHP application

2019-02-04 07:38发布

Is it possible to use Cucumber outside Rails? I'd like to start using it for testing some of my PHP applications, but I really don't know how to start.

Probably the easiest way would be creating a Rails project only to run Cucumber features, but that seems like to me as overkill.

What is the simplest way to set up Cucumber for testing a non-Rails application?

6条回答
Anthone
2楼-- · 2019-02-04 07:58

Checkout http://everzet.com/Behat/ (the URL appears to have changed to http://behat.org/)

查看更多
Deceive 欺骗
3楼-- · 2019-02-04 08:00

Cited from the cucumber website:

Cucumber works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 30 spoken languages.

查看更多
时光不老,我们不散
4楼-- · 2019-02-04 08:06

Behat, with Mink, PhantomJS and Sahi extensions, is a great BDD combo for php. If you are coming at it from a QA perspective, anyway.

查看更多
Fickle 薄情
5楼-- · 2019-02-04 08:07

You could definitely look at Behat and Mink. Behat is a runner for cucumber's Gherkin syntax (Given, When, Thens) and Mink lets Behat run real browsers. It provides you with a single API across several browser drivers, quite similar to Ruby's Capybara.

While using Cucumber and something like Webrat or Selenium to test a non Ruby application is ok, sticking with PHP if that's what your app is written has manifold benefits - developer skillset and ease of app setup (the kind of stuff you do in Given steps) being the most obvious.

查看更多
闹够了就滚
6楼-- · 2019-02-04 08:15

Check out:

https://github.com/cucumber/cucumber/wiki/php

It is easy to use cucumber with PHP, even managing the database.

查看更多
劫难
7楼-- · 2019-02-04 08:17

Here's a great example of how to functionally test a PHP Webapp using Cucumber ... it will show you how to set up your test folder and where to put steps http://jystewart.net/2008/11/10/testing-php-apps-with-ruby-tools/

Check out what this guy has done with Capybara.
Capbyara is a package that lets you choose your CLI browser driver - basically you can preface tests with @javascript and the Scenario will be played out using Selenium's very powerful chrome ... this allows you to smoothly test javascript where required!!! http://otaqui.com/blog/1072/testing-remote-php-websites-with-capybara-cucumber-mechanize-selenium-2-webdriver-and-saucelabs/

Further, I've been checking out this link, where the author uses Cuke4PHP to integrate PHPUnit with Cucumber ... this would then let you wrap PHPUnit tests in CucumberSteps ... allowing you to behaviorally test your application and DB using your existing PHP code http://lucato.it/php-bdd-cucumber-cuke4php

I myself am trying to meld all these pieces together into first a working and then robust test platform for a heavy-duty existing PHP webapp ... but I just began. Will update you if I make a good progress.

查看更多
登录 后发表回答