Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
unit-test your symfony forms against various sets of data defined in a YAML file.
PHP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
config
lib/test
test
LICENSE
README
README.markdown
package.xml.tmpl

README.markdown

rsFormTesterPlugin

test your symfony forms painless

Installation

git (recommend): git clone git@github.com:digitalkaoz/rsFormTesterPlugin.git

svn: svn co http://svn.github.com/digitalkaoz/rsFormTesterPlugin.git

pear: symfony plugin install rsFormTesterPlugin

enable the plugin in your config/ProjectConfiguration.class.php !

Configuration

configuration:
  unset: [foo, bazz/foo, bazz/bazz/bar]
  options: {foo: bar, bazz: foo}
  arguments: {foo: bazz}
  withSave: true
  formClass: fooForm
  verbose: true

pass:
  -
    _options: {foo: false, bazz: bar}
    _arguments: {foo: foo}
    foo: bar
    bar: bazz
    bazz:
      bar: foo
      foo: bar
  # ...
fail:
  -
    _expectedErrors: [foo, bazz, bazz/bar]
    foo:
    bar: bazz
    bazz:
      bar:
      foo: bar
  # ...
  • The unset options unsets specific widgets (i.e. captchas)

  • The formClass option defines which form the tester should instanciate.

  • The options defines a set of options passed to the form instanciation, can be overriden per set

  • The arguments defines a set of arguments passed to the form instanciation, can be overriden per set

  • The withSave option tests the invokation of sfForm::save.

  • The verbose option enables more detailed information on each test (recommended)

  • The pass options holds all different datasets which should pass the form validation.

  • The fail options holds all different datasets which should fail the form validation. the _expectedErrors options defines the errors you expect from the form. the verbose will show other errors as well.

Notice the foo/bar/bazz notation, thats how you define errors in embedded forms.

Usage

in your tests you are able to use the tester this way:

/* @var $t lime_test */

$tester = rsFormTester::create('path/to/config.yml');
$tester->testData($t);         #for both set
$tester->testData($t,'valid'); # for valid sets only
$tester->testData($t,'invalid'); # for invalid sets only

//or the short way
$tester = rsFormTester::create('path/to/config.yml')->testData($t);

Dont forget to increase the test count if you defined one!

If you will you can pass an already instanciated form to the tester (before runnning your tests)

$form = new FooBarForm($object,array('special_option'=>'foo'),array('special_arg'=>'bar'));
$tester->setForm($form);

//go on with your tests

That's it! All the different sets of data will be iterated and compared to what you expect

TODO

  • remove dependency to lime
Something went wrong with that request. Please try again.