sfPhpunitPlugin
1.0.1stable
for sf 1.2sf 1.1 MIT
The main idea of the plugin is to integrate phpunit and symfony more closer. Make the process of test writing more standard, flexible and easy for symfony developers. Another idea is to allow developers use features that only they want and not to inflict any extra requirments.
There are some main features.
* Flexible way to store and run tests.
* Manage fixtures, separate them to different folders.
* Manage symfony contexts.
* Configure phpunit in a symfony configuration way.
* Create testing infrastructure in one touch.
* Provide custom TestCases, for example, SeleniumTestCase, AmfTestCase.
Developers
| Name |
Status |
Email |
Pablo Godel |
lead |
moc.liamg <<ta>> ledogp
|
License
Copyright (c) 2008 Pablo Godel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Releases for sf 1.4
| Version |
License |
API |
Released |
|
1.0.20stable
|
MIT license |
1.2.0stable
|
13/05/2011 |
|
1.0.14stable
|
MIT license |
1.2.0stable
|
15/09/2010 |
|
1.0.13stable
|
MIT license |
1.2.0stable
|
09/08/2010 |
|
1.0.11stable
|
MIT license |
1.2.0stable
|
16/06/2010 |
|
1.0.10stable
|
MIT license |
1.2.0stable
|
04/06/2010 |
|
1.0.9stable
|
MIT license |
1.2.0stable
|
28/05/2010 |
Releases for sf 1.3
| Version |
License |
API |
Released |
|
1.0.20stable
|
MIT license |
1.2.0stable
|
13/05/2011 |
|
1.0.14stable
|
MIT license |
1.2.0stable
|
15/09/2010 |
|
1.0.13stable
|
MIT license |
1.2.0stable
|
09/08/2010 |
|
1.0.11stable
|
MIT license |
1.2.0stable
|
16/06/2010 |
|
1.0.10stable
|
MIT license |
1.2.0stable
|
04/06/2010 |
|
1.0.9stable
|
MIT license |
1.2.0stable
|
28/05/2010 |
Releases for sf 1.2
| Version |
License |
API |
Released |
|
1.0.20stable
|
MIT license |
1.2.0stable
|
13/05/2011 |
|
1.0.14stable
|
MIT license |
1.2.0stable
|
15/09/2010 |
|
1.0.13stable
|
MIT license |
1.2.0stable
|
09/08/2010 |
|
1.0.11stable
|
MIT license |
1.2.0stable
|
16/06/2010 |
|
1.0.10stable
|
MIT license |
1.2.0stable
|
04/06/2010 |
|
1.0.9stable
|
MIT license |
1.2.0stable
|
28/05/2010 |
|
1.0.8stable
|
MIT license |
1.2.0stable
|
20/01/2010 |
|
1.0.7stable
|
MIT license |
1.2.0stable
|
30/12/2009 |
|
1.0.4stable
|
MIT license |
1.2.0stable
|
19/01/2009 |
|
1.0.3stable
|
MIT license |
1.1.0stable
|
10/11/2008 |
|
1.0.2stable
|
MIT license |
1.1.0stable
|
10/11/2008 |
|
1.0.1stable
|
MIT license |
1.1.0stable
|
07/11/2008 |
Releases for sf 1.1
| Version |
License |
API |
Released |
|
1.0.4stable
|
MIT license |
1.2.0stable
|
19/01/2009 |
|
1.0.3stable
|
MIT license |
1.1.0stable
|
10/11/2008 |
|
1.0.2stable
|
MIT license |
1.1.0stable
|
10/11/2008 |
|
1.0.1stable
|
MIT license |
1.1.0stable
|
07/11/2008 |
|
0.0.1beta
|
MIT license |
0.0.1stable
|
06/11/2008 |
Releases for sf 1.0
| Version |
License |
API |
Released |
|
0.2.2devel
|
MIT license |
0.2.0devel
|
06/08/2010 |
Changelog for release 1.0.1 - 07/11/2008
- Added support for Doctrine
- Added model type option to arguments (propel/doctrine)
- Added connection name option to arguments
- Connection name and model path is determined by model type if it has not specified
- Removed incorrect Propel dependency in task
Other releases
Release 1.0.20 - 13/05/2011
- phpunit 3.5 support
- support oracle 10g
- fix doctrine fixture handling
- fix propel fixture handling
- prepared snapshots
Release 1.0.14 - 15/09/2010
- fix doctrine fixture handling
Release 1.0.13 - 09/08/2010
- improve plugin's test starting.
- replace preview release. it was missing some files
- make second paramter of getStub optional.
- fix _collect_coverage config option
Release 1.0.11 - 16/06/2010
- fix bugs on windows
- update documentation with link to example project
Release 1.0.10 - 04/06/2010
- fix doctrine fixture bug.
Release 1.0.9 - 28/05/2010
- own config file phpunit.yml
- fix fixture bugs.
- fix loader bugs.
- fix context managing bug.
- rewrite runtest task.
- improve test loader.
- plugin's test load.
- fix windows running problems.
Release 1.0.8 - 20/01/2010
- fix problems with running test under PHPUnit 3.3.x
- fix bug in sfPhpunit module
Release 1.0.7 - 30/12/2009
- remove requirments from the package.xml. it's a bad way to do so
Release 1.0.4 - 19/01/2009
- Make sure it can be installed on 1.2.x
Release 1.0.3 - 10/11/2008
- Fixed problem with phpunit not finding test/AllTests.php in some environments. (Thanks Dominik Masur for your help)
Release 1.0.2 - 10/11/2008
- Fixed problem with Doctrine Table test classes (Thanks Dominik Masur for your help)
Release 1.0.1 - 07/11/2008
- Added support for Doctrine
- Added model type option to arguments (propel/doctrine)
- Added connection name option to arguments
- Connection name and model path is determined by model type if it has not specified
- Removed incorrect Propel dependency in task
Release 0.2.2 - 06/08/2010
Release 0.0.1 - 06/11/2008
sfPhpunit plugin
The sfPhpunitPlugin is a symfony plugin that creates stub classes for PHPUnit of classes in lib/model (and other directories).
Symfony provides a testing framework, but many times it is necessary to use an existing PHPUnit installation. This plugin helps
creating the files necessary for PHPUnit to work with Symfony classes like Propel/Doctrine extended classes.
sfPhpunitPlugin does not create test methods for methods on the base classes of the generated model. It only creates test methods for the
custom methods added by the developer in the classes in lib/model.
sfPhpunitPlugin also creates an AllTests.php class file that can be used by PHPUnit to run all tests. This created file will include the creation
of the configuration object with the provided application name and create a connection to the database so propel based objects can be tested.
Installation & Usage
Install the plugin
$ symfony plugin:install sfPhpunitPlugin
Enable Plugin (Only for Symfony 1.2 and above)
Modify config/ProjectConfiguration.class.php
public function setup()
{
// for compatibility / remove and enable only the plugins you want
$this->enableAllPluginsExcept('sfDoctrinePlugin');
// or
$this->enablePlugins(array('sfPropelPlugin', 'sfPhpunitPlugin'));
$this->disablePlugins(array('sfDoctrinePlugin'));
}
Create all tests (Propel)
$ symfony phpunit:create application
This command will go over the lib/model directory and for each .php file it will create a fileTest.php in test/model/.
It will also create a test/AllTests.php that can be used to run all tests with symfony phpunit:testall or phpunit test/AllTests.php
The default database connection will be propel. You can change it by adding -c myConn
Create all tests (Doctrine)
$ symfony phpunit:create application --type=doctrine
This command will go over the lib/model/doctrine directory and for each .php file it will create a fileTest.php in test/model/.
It will also create a test/AllTests.php that can be used to run all tests with symfony phpunit:testall or phpunit test/AllTests.php
The default database connection will be doctrine. You can change it by adding -c myConn
Create tests for additional/other model directories
$ symfony phpunit:create application --model_path=apps/admin/lib
Create tests for a single model Class
$ symfony phpunit:create application --model=ClassName
Run all tests
$ symfony phpunit:testall
This is similar to running phpunit test/AllTests.php
Help of all arguments and options
$ symfony help phpunit:create
Example of AllTests.php
<?php
require_once 'PHPUnit/Framework.php';
define( 'SF_APP_NAME', 'admin' );
define( 'SF_ENV', 'test' );
define( 'SF_CONN', 'propel' );
if ( SF_APP_NAME != '' )
{
require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php');
AllTests::$configuration = ProjectConfiguration::getApplicationConfiguration( SF_APP_NAME , SF_ENV, true);
sfContext::createInstance(AllTests::$configuration);
}
class AllTests
{
public static $configuration = null;
public static $databaseManager = null;
public static $connection = null;
protected function setUp()
{
if ( self::$configuration )
{
// initialize database manager
self::$databaseManager = new sfDatabaseManager(self::$configuration);
self::$databaseManager->loadConfiguration();
if ( SF_CONN ) self::$connection = self::$databaseManager->getDatabase( SF_CONN );
}
}
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('PHPUnit');
$dir = new DirectoryIterator( dirname(__FILE__). '/model' );
while($dir->valid()) {
if( strpos( $dir, 'Test.php' ) !== false ) {
$suite->addTestFile( dirname(__FILE__). '/model/'. $dir );
}
$dir->next();
}
return $suite;
}
}
?>
Example of Test Class File
<?php
require_once 'PHPUnit/Framework.php';
class PinTest extends PHPUnit_Framework_TestCase
{
/**
* Pin
*
* @var Pin
*/
protected $o;
public function setup()
{
$this->o = new Pin();
}
public function testIsValid()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
public function testUpdateUse()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
}
?>
Customize sfPhpunitPlugin generated class files
By default, sfPhpunitPlugin comes with a set of templates to generate the stub class files, these are located inside the data plugin directory:
alltests_template.tpl - Template for generating AllTests.php file.
file_template.tpl - Template for generating the individual test class files.
method_template.tpl - Template for each test method inside the test class file.
TODO
- add support to run individual tests
- Contact me for any other requirements/ideas