Hi James,
You're right. In trunk, I replaced all symfony core unit
and functionnal
tests with a new testing framework (lime). This testing
framework is
more lighweight than PHPUnit or simpletest and has several
advantages:
the main one is that it launches test files in a sandbox to
avoid
strange effects between each test file run (one of the
reasons I was
unable to fix the old symfony core tests).
The new system also introduces a new sfBrowser,
sfTestBrowser and more
importantly sfDomCssSelectorBrowser that allow you to write
functionnal
tests with ease. It is not backward compatible but is a lot
more
powerful than the old system.
So, you can keep your unit tests written in simple test but
functionnal
tests that rely on the sfTestBrowser class have to be
upgraded.
Here is a simple usage example of the new sfTestBrowser
class:
define('SF_ROOT_DIR',
realpath(dirname(__FILE__).'/..'));
define('SF_APP', $app);
define('SF_ENVIRONMENT', 'test');
define('SF_DEBUG', true);
require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECT
ORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTOR
Y_SEPARATOR.'config.php');
$b = new sfTestBrowser();
$b->initialize();
// default main page
$b->
get('/')->
isStatusCode(200)->
isRequestParameter('module', 'default')->
isRequestParameter('action', 'index')->
checkResponseElement('body', '/congratulations/i')
;
The browser now has a fluent interface as you can see in the
above
example. This is the same as:
$b->get('/');
$b->isStatusCode(200);
$b->isRequestParameter('module', 'default');
$b->isRequestParameter('action', 'index');
$b->checkResponseElement('body',
'/congratulations/i');
The new system also gives you the response context for each
request, so
after doing a get() or a post(), you have access to the
context object
and some others:
$b->getContext()
$b->getResponse()
$b->getRequest()
You also have shortcuts for testing request parameters or
http headers:
$b->isRequestParameter('module', 'action');
$b->isResponseHeader('content-type', 'text/html;
charset=utf-8');
The new ->checkResponseElement() method is the more
powerful of the new
methods. It allows to test the response content by CSS
selectors. Here
are some examples (from sfDomCssSelectorTest unit test
file):
$t->is($c->getTexts('h1'), array('Test page'),
'->getTexts() takes a CSS
selector as its first argument');
$t->is($c->getTexts('h2'), array('Title 1',
'Title 2'), '->getTexts()
returns an array of matching texts');
$t->is($c->getTexts('#footer'), array('footer'),
'->getTexts() supports
searching html elements by id');
$t->is($c->getTexts('div#footer'),
array('footer'), '->getTexts()
supports searching html elements by id for a tag name');
$t->is($c->getTexts('.header'), array('header'),
'->getTexts() supports
searching html elements by class name');
$t->is($c->getTexts('p.header'), array('header'),
'->getTexts() supports
searching html elements by class name for a tag name');
$t->is($c->getTexts('div.header'), array(),
'->getTexts() supports
searching html elements by class name for a tag name');
$t->is($c->getTexts('.foo'),
array('multi-classes'), '->getTexts()
supports searching html elements by class name for
multi-class elements');
$t->is($c->getTexts('.bar'),
array('multi-classes'), '->getTexts()
supports searching html elements by class name for
multi-class elements');
$t->is($c->getTexts('.foobar'),
array('multi-classes'), '->getTexts()
supports searching html elements by class name for
multi-class elements');
$t->is($c->getTexts('ul#mylist ul li'),
array('element 3', 'element 4'),
'->getTexts() supports searching html elements by
several selectors');
$t->is($c->getTexts('ul#list li a[href]'),
array('link'), '->getTexts()
supports checking attribute existence');
$t->is($c->getTexts('ul#list li
a[class~="foo1"]'), array('link'),
'->getTexts() supports checking attribute word
matching');
$t->is($c->getTexts('ul#list li
a[class~="bar1"]'), array('link'),
'->getTexts() supports checking attribute word
matching');
$t->is($c->getTexts('ul#list li
a[class~="foobar1"]'), array('link'),
'->getTexts() supports checking attribute word
matching');
$t->is($c->getTexts('ul#list li
a[class^="foo1"]'), array('link'),
'->getTexts() supports checking attribute starting
with');
$t->is($c->getTexts('ul#list li
a[class$="foobar1"]'), array('link'),
'->getTexts() supports checking attribute ending
with');
$t->is($c->getTexts('ul#list li
a[class*="oba"]'), array('link'),
'->getTexts() supports checking attribute with *');
$t->is($c->getTexts('ul#anotherlist li
a[class|="bar1"]'),
array('another link'), '->getTexts() supports checking
attribute
starting with value followed by optional hyphen');
Fabien
James Goddard wrote:
> Fabien,
>
> I saw you recently committed "lime" into
the trunk. It appears to be a
> new unit testing framework. As a user using the latest
symfony &
> simpletest alpha's my unit tests are broken. What's
the scoop?
>
> Thanks!
>
> */"Ian P. Christian" <pookey pookey.co.uk>/* wrote:
>
> On 09/18/06 Zachary Kessin wrote:
> > We are trying to build an application around
symfony and we are
> > having issues around the fact that between
different versions
> > interfaces seem to change
>
> Please keep in mind that symfony is still pre-v1,
and whilst a lot of
> works goes into not breaking BC, sometimes changes
are made that will
> affect users. If you are developing a site and you
are updading symfony
> - you will need to pay reasonably close attention
to the change log.
>
> Thanks,
>
> --
> Ian P. Christian ~ http://pookey.co.uk
>
>
>
------------------------------------------------------------
------------
> Do you Yahoo!?
> Get on board. You're invited
> <http://us.rd.yahoo.com/evt=407
91/*http://advision.webevents.yahoo.com/mailbeta>
> to try the new Yahoo! Mail.
--
To unsubscribe, e-mail: dev-unsubscribe symfony-project.com
For additional commands, e-mail: dev-help symfony-project.com
|