added testcase for unit tests, bootstrap files improved, tests inherited from base testcase
This commit is contained in:
parent
805033eb4b
commit
e6ae361033
@ -1 +1,3 @@
|
||||
<?php
|
||||
|
||||
require_once(__DIR__.'/yii_bootstrap.php');
|
||||
|
56
tests/_helpers/TestCase.php
Normal file
56
tests/_helpers/TestCase.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace tests\_helpers;
|
||||
|
||||
class TestCase extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Your application config, will be merged with base config when creating application.
|
||||
* @var array
|
||||
*/
|
||||
protected $config = array();
|
||||
|
||||
/**
|
||||
* Created application class
|
||||
* @var string
|
||||
*/
|
||||
protected $appClass = '\yii\web\Application';
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->mockApplication();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->destroyApplication();
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
protected function mockApplication()
|
||||
{
|
||||
$baseConfig = require(__DIR__.'/../unit/_bootstrap.php');
|
||||
$config = \yii\helpers\ArrayHelper::merge($baseConfig,$this->config);
|
||||
new $this->appClass($config);
|
||||
}
|
||||
|
||||
protected function destroyApplication()
|
||||
{
|
||||
\Yii::$app = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method when you need to dump variables with var_dump function.
|
||||
* This is caused by the buffering output of the codeception.
|
||||
* @param mixed $var
|
||||
*/
|
||||
protected static function varDump($var)
|
||||
{
|
||||
ob_start();
|
||||
var_dump($var);
|
||||
\Codeception\Util\Debug::debug(ob_get_clean());
|
||||
}
|
||||
|
||||
}
|
@ -2,9 +2,7 @@
|
||||
|
||||
$config = require(__DIR__.'/../yii_bootstrap.php');
|
||||
|
||||
$config = yii\helpers\ArrayHelper::merge(
|
||||
return yii\helpers\ArrayHelper::merge(
|
||||
$config,
|
||||
require(__DIR__ . '/../../config/codeception/unit.php')
|
||||
);
|
||||
|
||||
$application = new yii\web\Application($config);
|
||||
|
@ -2,15 +2,7 @@
|
||||
|
||||
namespace tests\unit\models;
|
||||
|
||||
class ContactFormTest extends \PHPUnit_Framework_TestCase
|
||||
class ContactFormTest extends \tests\_helpers\TestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,15 +2,7 @@
|
||||
|
||||
namespace tests\unit\models;
|
||||
|
||||
class LoginFormTest extends \PHPUnit_Framework_TestCase
|
||||
class LoginFormTest extends \tests\_helpers\TestCase
|
||||
{
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
@ -4,7 +4,7 @@ namespace tests\unit\models;
|
||||
|
||||
#use yii\test\DbTestTrait;
|
||||
|
||||
class UserTest extends \PHPUnit_Framework_TestCase
|
||||
class UserTest extends \tests\_helpers\TestCase
|
||||
{
|
||||
|
||||
use DbTestTrait;
|
||||
@ -12,16 +12,14 @@ class UserTest extends \PHPUnit_Framework_TestCase
|
||||
protected function setUp()
|
||||
{
|
||||
/*
|
||||
*
|
||||
* you can load fixtures in this way
|
||||
*
|
||||
parent::setUp();
|
||||
$this->loadFixtures([
|
||||
'tbl_user',
|
||||
]);
|
||||
*/
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user