I am currently working with sfPhpUnitPlugin on a sf 1.4 project, and I am facing a problem with plugin testing.
I have a plugin that can be used on several applications, and I would like to have a test suite per application. How can I organize my tests so that I can easily match fixtures and tests with a specific application?
My suites are copies of this template, which is delivered with the sfPhpunitPlugin:
<?php
class {className} extends sfBasePhpunitTestSuite
implements sfPhpunitContextInitilizerInterface
{
/**
* Dev hook for custom "setUp" stuff
*/
protected function _start()
{
$this->_initFilters();
}
/**
* Dev hook for custom "tearDown" stuff
*/
protected function _end()
{
}
protected function _initFilters()
{
$filters = sfConfig::get('app_sfPhpunitPlugin_filter', array());
foreach ($filters as $filter) {
PHPUnit_Util_Filter::addDirectoryToFilter($filter['path'], $filter['ext']);
}
}
public function getApplication()
{
return '{application}';
}
}
I suppose I have to add something like this in the app.yml of each application:
testunit:
sfPhpunitPlugin:
filter:
- {path: 'backend', ext: '.php'}
but I have difficulty determining what the path key is going to look like, I'm under the impression it should be a full path, because the include_path does not contain the path of the plugin I'm testing wh开发者_运维问答en addDirectoryToFilter()
is called.
Any tips?
Has anyone done this yet?
Actually You have to create two suite classes which implemented sfPhpunitContextInitilizerInterface interface and implement all required methods.
Then put those two suites in two different folders, for example:
SF_PLUGIN_DIR/YOUR_PLUGIN/test/phpunit/unit/app1/App1TestSuite.php SF_PLUGIN_DIR/YOUR_PLUGIN/test/phpunit/unit/app2/App2TestSuite.php
All tests in directory app1 or subdirectories will be run in symfony app defined in App1TestSuite.php and the same rules for app2 directory.
If you want to run tests dynamically in different applications you can define this logic in methods required by interface (getEnviroment and getApplication).
Feel free to ask me if you still have any questions.
精彩评论