Testing PHP apps with Ruby tools

As I’ve mentioned here before, when working on web applications built with PHP, whether custom-rolled or drupal-driven, I often find myself missing various tools from the ruby kit. I’ve talked before about using capistrano with non-ruby code, but lately it’s been rspec and its stories that I’ve been craving.

I’m aware of PHPSpec and have played with it from time to time, but the lack of a compelling way to work with mocks/stubs has slowed my adoption, and last time I checked it didn’t offer anything for high level user stories. So this week I set out to harness cucumber and webrat to write some simple stories.

It turns out to be pretty easy. There’s no nice simple support for test environments, fixtures, mocks or stubs, but if you just want to make sure that a few pages load correctly, and have the right elements, or that logging in works as you expected, then it’ll do the job.

I’ve not done any packaging up of the code, mainly because there’s so little to it. My folder structure is:

specs/
  Rakefile
  features/
    admin_articles.feature
    steps/
      admin_steps.rb

(click on the links to see sample files)

I simply set up those files, go into the folder and type ‘rake features’ to put your site through its paces.

Tags: , , , , , ,

1 comment

  1. Thanks that is something i have been thinking for a while, bdd testing is php is always harder than rails, I have previously attempted to fix this in a small scale by implementing a subclass(SimpleSpec) of SimpleTest, it looks quite decent compare to PhpSpec in my opinion, http://github.com/speedmax/h2o-php/blob/0843d30434d2e04c17e8a1dc81049ca22d2343b6/specs/context_spec.php

    cucumber + webrat seems like a good try for high level testing (features/stories),

    Will be cool if we can get rspec working to test php objects, for object invocation and stuff.

    i am feeling like
    (jruby + projectzero) or (jruby + Quercus )

    anyone like this idea? we can put up a github project