Code Monkey home page Code Monkey logo

cakebehat's Introduction

CakeBehat is shell for testing CakePHP Application by Behat

Copyright© 2011 Sizuhiko. Licensed under the MIT license.

Overview

Behat is PHP version clone of famous BDD framework cucumber in Ruby on Rails.
The advantage are followings:

  • Customer are able to read & understand because the scenarios written by the natural language
  • Scenario is executable as test !

The test of a current CakePHP application
1. SimpleTest in the unit test
2. Selenium might have been used in the test of the browser base.
And, it became possible to be doing the acceptance test (In customer’s word) by Behat/Mink in the future.

However, Behat is Symfony base, and, up to now, the plug-in etc. to execute the application of CakePHP have not been prepared.

Then, the shell task of executing it by “cake behat” like “rake cucumber” was made.
It is “CakeBehat” shell.

Usage

Require

  • PHPUnit
  • CakePHP 2.0 or later
  • The data base such as MySQL must be installed, and the data base for the test must be prepared.
  • PHP 5.3.2 or later
  • Behat 2.1.3 and Mink (auto install by CakeBehat.init)

Install

Under the plugins directory of CakePHP root, execute the following commands.


cd plugins
git clone [email protected]:sizuhiko/CakeBehat.git
cd ..

Then, add the following code in app/Config/bootstrap.php


CakePlugin::load('CakeBehat');

Next, the following commands are executed. (on root of CakePHP)


ls
  app  index.php  lib  plugins  vendors

lib/Cake/Console/cake CakeBehat.init

The initial install is an end.

Configuration

Setting your application root url into behat.yml.


app/Config/behat.yml

base_url: http://test.localhost:8888/application-name/

This specifies the host name, the port number, and the application name, etc. by the one to set passing the route of the application. Setting it to the host name that can be identified to the test environment as much as possible is recommended.

Do you end by this?

A basic environmental setting ends by this. Behat is an executable situation.

Your application database settings.

An initial value of config/database.php is $default.
When UnitTest is executed, $test might already been defined.
Behat/Mink is executed by the browser access. Data base ($test) for the test cannot access to without the change in the setting.

When test step registers the test data, CakeBehat uses $test. Therefore, the definition is needed without fail. My recommendation is that the data base setting is switched by the environment like “Easy peasy database config” of Bakery.
http://bakery.cakephp.org/articles/joelmoss/2006/11/16/easy-peasy-database-config

In sample application (sample) of the inclusion, it switch based on the accessed server name.
When the accessed host name is test.localhost, the data base for test is used.
When it is not so, the data base for development is used.
It will become possible to use test.localhost if it set “127.0.0.1 localhost and test.localhost” into the hosts file. It is easy.

How to insert test data

CakeBehat has two methods that can be used with the step file.

  • truncateModel() : Method for deletion of test data.
  • getModel() Method of getting model to register test data.

$steps->Given('/^there is a post:$/', function($world, $table) {
  $hash = $table->getHash();
  $world->truncateModel('Post');
  $post = $world->getModel('Post');
  foreach ($hash as $row) {
	$post->create(array('Post'=>array('title'=>$row['Title'], 'body'=>$row['Body'])));
	$post->save();
  }
});

Let’s execute it.

Move to the directory including lib, app, and plugins, and next, execute the following commands.
lib/Cake/Console/cake CakeBehat.bdd

You can use any of behat options.
Please check
lib/Cake/Console/cake CakeBehat.bdd --help

The command operates only by the directory that includes app, lib, plugins and vendors, etc.
Please note it.

Sample code

https://github.com/sizuhiko/CakeBehatExampleApp

It include English and Japanese features.

cakebehat's People

Contributors

abe4tawa8 avatar sizuhiko avatar mtak3 avatar

Watchers

mogmo avatar James Cloos avatar  avatar mkoike avatar  avatar Akihito Sugano avatar NISHIMURA Daisuke avatar Furuya, Nozomu avatar Nobuhiro Kikuchi avatar  avatar Yui Sakamoto avatar Kazuhiko Hotta avatar Chotatsu Zukeran avatar  avatar  avatar Park JY avatar tyrell-chiba avatar  avatar LisaTakahashi avatar  avatar HiromiYamada avatar Toyonari Deushi avatar y-takase avatar  avatar Mochizuki Takahiro avatar Daisuke Yamashiro avatar  avatar  avatar  avatar 高津英輔 avatar  avatar  avatar  avatar  avatar Yūsuke Morita avatar Mika Okada avatar  avatar  avatar HackOn avatar  avatar Yasutoshi Okamoto avatar  avatar n-sekiguchi avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.