Behavior Driven Development and PHP applications - php

I am in love with Cucumber. It's easily configured for a Ruby on Rails application. However, I'm new to Ruby and so is the rest of my team. We are writing PHP applications using the Zend Framework. I'm interested in hearing how you have implemented BDD for your PHP applications and what frameworks/libraries I should use. Have you configured Cucumber? Or are you using a different library?

Cuke4PHP
Cuke4PHP implements the Cucumber wire protocol, making it possible to write step definitions in PHP. This means you can write some (or most) of your step definitions in Ruby and write the other step definitions in PHP (the ones that have to do with modifying the database).
Another alternative is..
Behat
Behat is a port of Cucumber written in PHP 5.3. Unfortunately, it requires PHP 5.3, so if your environment is not set up for PHP 5.3, you won't be able to use this.

I've successfully ran cucumber with PHP step definitions using cuke4php. But the Windows users on our dev team could not run cuke4php because they ran into a problem with ruby and fork(2) on that platform.
Running fork(2) from Windows with Cygwin. Possible?

Related

PHP Workflow Engine Framework

Is ezComponent Workflow still actively being developed? I've downloaded their code and attempted to get everything working (using postgres db, php 5.4), but it continually fails with their sample code. That being said, are there any mature PHP based Workflow Engine implementations out there that you can recommend?
ezComponents are now known as Zeta Components.
See http://zetacomponents.org/ -- Quote: Zeta Components originally were developed by eZ Systems under the name "eZ Components" and was generously sponsored to the Apache Software Foundation for further development. Since 07/2010 the components are known as "Zeta Components"
This would explain why you're not seeing any updates to the main ezComponents site, because all new development work is being done under the Zeta Components project.

Ruby on Rails or PHP Framework for a Java developer

I am aiming to write up a web service program in either a PHP framework (such as CakePHP or Yii) or writing it up in Ruby on Rail.
I have experience in Java and Perl. One of the thing I really like about Java is Eclipse - it was made for Java and is really helpful when handling objects. Although Perl has its plugin for Eclipse, it is no where as good as using Eclipse for Java.
My question is which framework would I be better off - Yii/CakePhp or Ruby On Rails. I gave Yii a try, an it took me minutes to set up php objects based on the SQL tables. I was wondering if Ruby On Rails is that easy. Although it looks like there is more support for Ruby On Rails ...
And does Eclipse integrate well with either Ruby On Rails or Yii? eg. by typing object name followed by a dot, I can see the attributes of the object in a drop down list.
Thanks!
I was Java developer and migrated to Ruby On Rails 2 years ago and I'm happy! I offer to use it for your work because:
It has a big community, as you have already seen
It has a wonderful support
It goes with new web technologies (HTML5/CSS3, Twitter bootstrap and etc.)
It is object related language as Java
It updates VERY FAST
And does Eclipse integrate well with either Ruby On Rails?
You can use Rubymine (Ideja) or Aptana (the same as Eclipe)
eg. by typing object name followed by a dot, I can see the attributes of the object in a drop down list.
Yes, but it works buggy because Ruby is not typed language
For Ruby On Rails I offer use TextMate or Vim (Gvim, MacVim)
I prefer ruby on rails first, if you want to spend time on php frameworks try cakePHP latest version, codeIgniter (easy to use) but my feelings - whatever technologies we used - some good principle comes with Ruby On Rails framework like
Test Driven Development
Behavior Driven Development
Pair programming
Don’t Repeat Yourself” (DRY) - removing the repetition code
these type of concepts and Agile Methodology if we implement in php, java or any Dynamic Programming language no need to migrate but I am agree to say depend on business logic we can choose language.
You can't go wrong with yii if it's php but I'd say rails. I was in the same situation you're in and never looked back since switching to rails.
Yii 2 will soon be out by the way but rails receives updates really fast and the support on here is incredible. I'm quite sure I would have lost patience with rails if it wasn't for the support I receive here.
I crunch PHP all day but i would go with Rails due to the environment surrounding it.
Ruby has RubyGems = awesome package / dependency management.
PHP has Pear and PECL = headaches.
Rails has Rspec and cucumber for TDD which are awesome.
PHP has PHPunit which is an admirable effort but requires tons of configuration.
Rails has a console for scaffolding, migrations etc that is far better than any PHP framework i have used.

Are there any php frameworks contain small webserver and rich console tools like RoR/Django?

In Ruby on Rails, I can start my web application, just write in console: script/server.
RoR contains small webserver and rich console tools, but I didn`t meet such tools in php frameworks.
Are there any php frameworks contain small webserver and rich console tools?
Neither PHP, nor any of the PHP frameworks bring their own webserver. Some frameworks offer rake like tools like Cake's bake or ZF's Zend_Tool. There is also Phing and Pake that are not specific to a framework. The closest to Gem in PHP is PEAR. You can start PHP in interactive mode from the shell with php -a
As of PHP 5.4 PHP also has it's own internal werbserver, which you can start from CLI with
php -S localhost:8000
You can read more about that feature at http://php.net/manual/en/features.commandline.webserver.php
CakePHP is the closest. Your models/views/controllers directories will be the same. All of the concepts like routes, active record, plugins, and scaffolding are similar. The active record implementation supports associated models (one-to-many, many-to-many, etc). This is something that is lacking in other php ORM implementations.
Here's an old (April 2007) Ask Metafilter that had some folks contributing frameworks to look at: CakePHP, Symfony, Mojavi, Code Igniter are the PHP MVC frameworks recommended. They suggested CI and Symfony over Cake.

Cucumber for PHP application

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?
Check out:
https://github.com/cucumber/cucumber/wiki/php
It is easy to use cucumber with PHP, even managing the database.
Checkout http://everzet.com/Behat/
(the URL appears to have changed to http://behat.org/)
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.
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.
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.
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.

How do you handle library dependencies during deployment using PHP?

this is a question on PHP mainly. I was wondering: How do you make sure that all necessary libaries are packaged with your application when you do a deployment to (production) servers?
A more concrete example: I have an app running on Zend Framework and each time I roll the application to a server the deployment process creates a fresh "installation" on that system. Therefore, I need to bundle Zend Framework together with my application and then copy the files to the right places together (it is done automatically). Currently, I am using a svn:externals definition to get the files out of Zend's SVN system during deployment, however, I don't want to rely on that SVN and I also don't want to put traffic on external SVNs with each deployment.
In the Java world, I am used to Maven which handles such stuff using central artifact repositries. I know that there is a Maven4PHP version, however, I am more looking for a PHP-based solution. Additionally, I don't believe that PEAR is a good way to go as it doesn't really fulfill my requirement of bundling the applicaiton (incl. libs) into a single deployable.
Is there some tool available already that I am not aware? Or do you have any great technique that I should know?
Thanks much for your help!
Michael
There's a build system called Phing which is written in PHP and based on Apache Ant.
I personally can very well live with externals.
I think the vendor branching would solve the problem from your example quite straightforward, but if you also don't like large repositories I'd recommended to keep watching on the modern toys like composer and what it solve(and maybe phark, I never heard before :) )
It isn't production ready yet but you might want to keep an eye on the Phark project. It is a port of Bundler to PHP.
While looking through the Simplify your external dependency management slides I came across a tool called pantr which can be used as a PEAR installer. pantr as PEAR installer which allows you to specify your dependencies in a project specific file.
The article Version Control != Dependency Management has some information about using the new PEAR installer called Pyrus

Categories