Browse Source

cleanup tests

tags/2.0.0-beta
Carsten Brandt 12 years ago
parent
commit
cb8f5d702f
  1. 1
      tests/unit/DatabaseTestCase.php
  2. 1
      tests/unit/MysqlTestCase.php
  3. 33
      tests/unit/TestCase.php
  4. 6
      tests/unit/framework/YiiBaseTest.php
  5. 6
      tests/unit/framework/base/ComponentTest.php
  6. 6
      tests/unit/framework/base/DictionaryTest.php
  7. 6
      tests/unit/framework/base/ObjectTest.php
  8. 6
      tests/unit/framework/base/VectorTest.php
  9. 2
      tests/unit/framework/db/ActiveRecordTest.php
  10. 2
      tests/unit/framework/db/sqlite/SqliteActiveRecordTest.php
  11. 4
      tests/unit/framework/db/sqlite/SqliteCommandTest.php
  12. 10
      tests/unit/framework/db/sqlite/SqliteConnectionTest.php
  13. 2
      tests/unit/framework/db/sqlite/SqliteQueryTest.php
  14. 3
      tests/unit/framework/helpers/HtmlTest.php
  15. 3
      tests/unit/framework/helpers/VarDumperTest.php
  16. 9
      tests/unit/framework/rbac/PhpManagerTest.php

1
tests/unit/DatabaseTestCase.php

@ -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;

1
tests/unit/MysqlTestCase.php

@ -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.');
}

33
tests/unit/TestCase.php

@ -2,20 +2,29 @@
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();
}
/**
* 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) {
@ -24,7 +33,12 @@ class TestCase extends \yii\test\TestCase
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;
}

6
tests/unit/framework/YiiBaseTest.php

@ -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;
}

6
tests/unit/framework/base/ComponentTest.php

@ -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;
}

6
tests/unit/framework/base/DictionaryTest.php

@ -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;

6
tests/unit/framework/base/ObjectTest.php

@ -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;
}

6
tests/unit/framework/base/VectorTest.php

@ -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;

2
tests/unit/framework/db/ActiveRecordTest.php

@ -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();

2
tests/unit/framework/db/sqlite/SqliteActiveRecordTest.php

@ -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
tests/unit/framework/db/sqlite/SqliteCommandTest.php

@ -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);

10
tests/unit/framework/db/sqlite/SqliteConnectionTest.php

@ -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'));

2
tests/unit/framework/db/sqlite/SqliteQueryTest.php

@ -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();

3
tests/unit/framework/helpers/HtmlTest.php

@ -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(

3
tests/unit/framework/helpers/VarDumperTest.php

@ -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();
}
}

9
tests/unit/framework/rbac/PhpManagerTest.php

@ -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);
}

Loading…
Cancel
Save