Permalink
Browse files

Added support for creating test skeleton files.

  • Loading branch information...
1 parent ed259c3 commit 6d19e4b18b0117e430a3316a26d3a66dc3eba5dd qiang.xue committed Jun 12, 2009
@@ -61,6 +61,8 @@ public function run($args)
die('Unable to locate the source directory.');
$list=$this->buildFileList($sourceDir,$path);
$list['index.php']['callback']=array($this,'generateIndex');
+ $list['protected/tests/unit/bootstrap.php']['callback']=array($this,'generateTestBoostrap');
+ $list['protected/tests/functional/bootstrap.php']['callback']=array($this,'generateTestBoostrap');
$list['protected/yiic.php']['callback']=array($this,'generateYiic');
$this->copyFiles($list);
@chmod($path.'/assets',0777);
@@ -79,6 +81,15 @@ public function generateIndex($source,$params)
return preg_replace('/\$yii\s*=(.*?);/',"\$yii=$yii;",$content);
}
+ public function generateTestBoostrap($source,$params)
+ {
+ $content=file_get_contents($source);
+ $yii=realpath(dirname(__FILE__).'/../../yii.php');
+ $yii=$this->getRelativePath($yii,$this->_rootPath.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'unit'.DIRECTORY_SEPARATOR.'index.php');
+ $yii=str_replace('\\','\\\\',$yii);
+ return preg_replace('/\$yii\s*=(.*?);/',"\$yii=$yii;",$content);
+ }
+
public function generateYiic($source,$params)
{
$content=file_get_contents($source);
@@ -0,0 +1,17 @@
+<?php
+
+return CMap::mergeArray(
+ require(dirname(__FILE__).'/main.php'),
+ array(
+ 'components'=>array(
+ 'fixture'=>array(
+ 'class'=>'system.test.CDbFixtureManager',
+ ),
+ /* uncomment the following to provide test database connection
+ 'db'=>array(
+ 'connectionString'=>'xyz',
+ ),
+ */
+ ),
+ )
+);
@@ -0,0 +1,21 @@
+<?php
+
+// change the following paths if necessary
+$yii=dirname(__FILE__).'/../../../../framework/yii.php';
+$config=dirname(__FILE__).'/../../config/test.php';
+
+// disable Yii error handling logic
+defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER',false);
+defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER',false);
+
+// the following server variables are defined to simulate Web-based execution
+$_SERVER['SCRIPT_NAME']='/'.basename(__FILE__);
+$_SERVER['SCRIPT_FILENAME']=__FILE__;
+
+require_once($yii);
+
+Yii::import('system.test.CTestCase');
+Yii::import('system.test.CDbTestCase');
+Yii::import('system.test.CWebTestCase');
+
+Yii::createWebApplication($config);
@@ -0,0 +1,8 @@
+<phpunit bootstrap="bootstrap.php"
+ colors="false"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnFailure="false">
+
+</phpunit>
@@ -0,0 +1,20 @@
+<?php
+
+// change the following paths if necessary
+$yii=dirname(__FILE__).'/../../../../framework/yii.php';
+$config=dirname(__FILE__).'/../../config/test.php';
+
+// disable Yii error handling logic
+defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER',false);
+defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER',false);
+
+// the following server variables are defined to simulate Web-based execution
+$_SERVER['SCRIPT_NAME']='/'.basename(__FILE__);
+$_SERVER['SCRIPT_FILENAME']=__FILE__;
+
+require_once($yii);
+
+Yii::import('system.test.CTestCase');
+Yii::import('system.test.CDbTestCase');
+
+Yii::createWebApplication($config);
@@ -0,0 +1,12 @@
+<phpunit bootstrap="bootstrap.php"
+ colors="false"
+ convertErrorsToExceptions="true"
+ convertNoticesToExceptions="true"
+ convertWarningsToExceptions="true"
+ stopOnFailure="false">
+
+ <testsuite name="My unit tests">
+ <directory>./models</directory>
+ </testsuite>
+
+</phpunit>
@@ -88,7 +88,7 @@ public function getFixtureManager()
* If you override this method, make sure the parent implementation is invoked.
* Otherwise, the database fixtures will not be managed properly.
*/
- public function setUp()
+ protected function setUp()
{
parent::setUp();
$this->getFixtureManager()->load($this->fixtures);
@@ -57,7 +57,7 @@ public function __call($name,$params)
if(isset($params[0]) && ($record=$this->getFixtureManager()->getRecord($name,$params[0]))!==false)
return $record;
else
- throw new Exception("Unknown method '$name' for class '".get_class($this)."'.");
+ return parent::__call($name,$params);
}
/**
@@ -73,7 +73,7 @@ public function getFixtureManager()
* If you override this method, make sure the parent implementation is invoked.
* Otherwise, the database fixtures will not be managed properly.
*/
- public function setUp()
+ protected function setUp()
{
parent::setUp();
$this->getFixtureManager()->load($this->fixtures);

0 comments on commit 6d19e4b

Please sign in to comment.