![]() |
|
sfPhpunitPlugin - 1.0.1symfony Phpunit plugin |
|
![]() |
38
users
Sign-in
to change your status |
Symfony plugin that creates stub classes for PHPUnit of classes in lib/model |
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.
| Name | Status | |
|---|---|---|
|
|
lead | moc.liamg <<ta>> ledogp |
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.
| 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 |
| 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 |
| 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 |
| 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 |
| Version | License | API | Released |
|---|---|---|---|
| 0.2.2devel | MIT license | 0.2.0devel | 06/08/2010 |
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.
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
<?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; } } ?>
<?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.' ); } } ?>
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.