Commit cb8f5d70 by Carsten Brandt

cleanup tests

parent e0ad7125
......@@ -10,6 +10,7 @@ class DatabaseTestCase extends TestCase
protected function setUp()
{
parent::setUp();
$databases = $this->getParam('databases');
$this->database = $databases[$this->driverName];
$pdo_database = 'pdo_'.$this->driverName;
......
......@@ -6,6 +6,7 @@ class MysqlTestCase extends TestCase
{
protected function setUp()
{
parent::setUp();
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) {
$this->markTestSkipped('pdo and pdo_mysql extensions are required.');
}
......
......@@ -2,29 +2,43 @@
namespace yiiunit;
/**
* This is the base class for all yii framework unit tests.
*/
class TestCase extends \yii\test\TestCase
{
public static $params;
protected function setUp() {
parent::setUp();
}
/**
* Clean up after test.
* By default the application created with [[mockApplication]] will be destroyed.
*/
protected function tearDown()
{
parent::tearDown();
$this->destroyApp();
$this->destroyApplication();
}
public function getParam($name,$default=null)
/**
* Returns a test configuration param from /data/config.php
* @param string $name params name
* @param mixed $default default value to use when param is not set.
* @return mixed the value of the configuration param
*/
public function getParam($name, $default = null)
{
if (self::$params === null) {
self::$params = require(__DIR__ . '/data/config.php');
}
return isset(self::$params[$name]) ? self::$params[$name] : $default;
}
protected function mockApplication($requiredConfig=array())
/**
* Populates Yii::$app with a new application
* The application will be destroyed on tearDown() automatically.
* @param array $config The application configuration, if needed
*/
protected function mockApplication($config=array())
{
static $defaultConfig = array(
'id' => 'testapp',
......@@ -32,10 +46,13 @@ class TestCase extends \yii\test\TestCase
);
$appClass = $this->getParam( 'appClass', '\yii\web\Application' );
new $appClass(array_merge($defaultConfig,$requiredConfig));
new $appClass(array_merge($defaultConfig,$config));
}
protected function destroyApp()
/**
* Destroys application in Yii::$app by setting it to null.
*/
protected function destroyApplication()
{
\Yii::$app = null;
}
......
......@@ -11,13 +11,15 @@ class YiiBaseTest extends TestCase
{
public $aliases;
public function setUp()
protected function setUp()
{
parent::setUp();
$this->aliases = Yii::$aliases;
}
public function tearDown()
protected function tearDown()
{
parent::tearDown();
Yii::$aliases = $this->aliases;
}
......
......@@ -24,13 +24,15 @@ class ComponentTest extends TestCase
*/
protected $component;
public function setUp()
protected function setUp()
{
parent::setUp();
$this->component = new NewComponent();
}
public function tearDown()
protected function tearDown()
{
parent::tearDown();
$this->component = null;
}
......
......@@ -19,8 +19,9 @@ class DictionaryTest extends \yiiunit\TestCase
protected $item2;
protected $item3;
public function setUp()
protected function setUp()
{
parent::setUp();
$this->dictionary = new Dictionary;
$this->item1 = new MapItem;
$this->item2 = new MapItem;
......@@ -29,8 +30,9 @@ class DictionaryTest extends \yiiunit\TestCase
$this->dictionary->add('key2', $this->item2);
}
public function tearDown()
protected function tearDown()
{
parent::tearDown();
$this->dictionary = null;
$this->item1 = null;
$this->item2 = null;
......
......@@ -14,13 +14,15 @@ class ObjectTest extends TestCase
*/
protected $object;
public function setUp()
protected function setUp()
{
parent::setUp();
$this->object = new NewObject;
}
public function tearDown()
protected function tearDown()
{
parent::tearDown();
$this->object = null;
}
......
......@@ -19,8 +19,9 @@ class VectorTest extends \yiiunit\TestCase
protected $item2;
protected $item3;
public function setUp()
protected function setUp()
{
parent::setUp();
$this->vector = new Vector;
$this->item1 = new ListItem;
$this->item2 = new ListItem;
......@@ -29,8 +30,9 @@ class VectorTest extends \yiiunit\TestCase
$this->vector->add($this->item2);
}
public function tearDown()
protected function tearDown()
{
parent::tearDown();
$this->vector = null;
$this->item1 = null;
$this->item2 = null;
......
......@@ -12,7 +12,7 @@ use yiiunit\data\ar\Item;
class ActiveRecordTest extends \yiiunit\DatabaseTestCase
{
public function setUp()
protected function setUp()
{
parent::setUp();
ActiveRecord::$db = $this->getConnection();
......
......@@ -4,7 +4,7 @@ namespace yiiunit\framework\db\sqlite;
class SqliteActiveRecordTest extends \yiiunit\framework\db\ActiveRecordTest
{
public function setUp()
protected function setUp()
{
$this->driverName = 'sqlite';
parent::setUp();
......
......@@ -4,13 +4,13 @@ namespace yiiunit\framework\db\sqlite;
class SqliteCommandTest extends \yiiunit\framework\db\CommandTest
{
public function setUp()
protected function setUp()
{
$this->driverName = 'sqlite';
parent::setUp();
}
function testAutoQuoting()
public function testAutoQuoting()
{
$db = $this->getConnection(false);
......
......@@ -4,13 +4,13 @@ namespace yiiunit\framework\db\sqlite;
class SqliteConnectionTest extends \yiiunit\framework\db\ConnectionTest
{
public function setUp()
protected function setUp()
{
$this->driverName = 'sqlite';
parent::setUp();
}
function testConstruct()
public function testConstruct()
{
$connection = $this->getConnection(false);
$params = $this->database;
......@@ -18,7 +18,7 @@ class SqliteConnectionTest extends \yiiunit\framework\db\ConnectionTest
$this->assertEquals($params['dsn'], $connection->dsn);
}
function testQuoteValue()
public function testQuoteValue()
{
$connection = $this->getConnection(false);
$this->assertEquals(123, $connection->quoteValue(123));
......@@ -26,7 +26,7 @@ class SqliteConnectionTest extends \yiiunit\framework\db\ConnectionTest
$this->assertEquals("'It''s interesting'", $connection->quoteValue("It's interesting"));
}
function testQuoteTableName()
public function testQuoteTableName()
{
$connection = $this->getConnection(false);
$this->assertEquals("'table'", $connection->quoteTableName('table'));
......@@ -35,7 +35,7 @@ class SqliteConnectionTest extends \yiiunit\framework\db\ConnectionTest
$this->assertEquals('(table)', $connection->quoteTableName('(table)'));
}
function testQuoteColumnName()
public function testQuoteColumnName()
{
$connection = $this->getConnection(false);
$this->assertEquals('"column"', $connection->quoteColumnName('column'));
......
......@@ -12,7 +12,7 @@ namespace yiiunit\framework\db\sqlite;
class SqliteQueryTest extends \yiiunit\framework\db\QueryTest
{
public function setUp()
protected function setUp()
{
$this->driverName = 'sqlite';
parent::setUp();
......
......@@ -8,8 +8,9 @@ use yiiunit\TestCase;
class HtmlTest extends TestCase
{
public function setUp()
protected function setUp()
{
parent::setUp();
$this->mockApplication(array(
'components' => array(
'request' => array(
......
......@@ -7,6 +7,9 @@ class VarDumperTest extends \yii\test\TestCase
public function testDumpObject()
{
$obj = new \StdClass();
ob_start();
VarDumper::dump($obj);
$this->assertEquals("stdClass#1\n(\n)", ob_get_contents());
ob_end_clean();
}
}
......@@ -5,12 +5,14 @@ namespace yiiunit\framework\rbac;
use Yii;
use yii\rbac\PhpManager;
require_once(__DIR__ . '/ManagerTestBase.php');
//require_once(__DIR__ . '/ManagerTestBase.php');
class PhpManagerTest extends ManagerTestBase
{
public function setUp()
protected function setUp()
{
parent::setUp();
$this->mockApplication();
$authFile = Yii::$app->getRuntimePath() . '/rbac.php';
@unlink($authFile);
$this->auth = new PhpManager;
......@@ -19,8 +21,9 @@ class PhpManagerTest extends ManagerTestBase
$this->prepareData();
}
public function tearDown()
protected function tearDown()
{
parent::tearDown();
@unlink($this->auth->authFile);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment