mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-09 17:57:38 +08:00
Improved console controller tests
This commit is contained in:
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace yiiunit\extensions\mongodb\console\controllers;
|
||||
|
||||
use yii\mongodb\console\controllers\MigrateController;
|
||||
|
||||
/**
|
||||
* MigrateController that writes output via echo instead of using output stream. Allows us to buffer it.
|
||||
*/
|
||||
class EchoMigrateController extends MigrateController
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function stdout($string)
|
||||
{
|
||||
echo $string;
|
||||
}
|
||||
}
|
||||
@ -8,7 +8,6 @@ use yii\mongodb\Query;
|
||||
use Yii;
|
||||
use yiiunit\extensions\mongodb\MongoDbTestCase;
|
||||
use yiiunit\framework\console\controllers\MigrateControllerTestTrait;
|
||||
use yii\mongodb\console\controllers\MigrateController;
|
||||
|
||||
/**
|
||||
* Unit test for [[\yii\mongodb\console\controllers\MigrateController]].
|
||||
@ -23,7 +22,7 @@ class MigrateControllerTest extends MongoDbTestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->migrateControllerClass = MigrateController::className();
|
||||
$this->migrateControllerClass = EchoMigrateController::className();
|
||||
$this->migrationBaseClass = Migration::className();
|
||||
|
||||
parent::setUp();
|
||||
|
||||
@ -16,7 +16,7 @@ class CacheControllerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var \yiiunit\framework\console\controllers\CacheConsoledController
|
||||
* @var SilencedCacheController
|
||||
*/
|
||||
private $_cacheController;
|
||||
|
||||
@ -27,7 +27,7 @@ class CacheControllerTest extends TestCase
|
||||
parent::setUp();
|
||||
|
||||
$this->_cacheController = Yii::createObject([
|
||||
'class' => 'yiiunit\framework\console\controllers\CacheConsoledController',
|
||||
'class' => 'yiiunit\framework\console\controllers\SilencedCacheController',
|
||||
'interactive' => false,
|
||||
],[null, null]); //id and module are null
|
||||
|
||||
@ -122,7 +122,7 @@ class CacheControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException yii\console\Exception
|
||||
* @expectedException \yii\console\Exception
|
||||
*/
|
||||
public function testNothingToFlushException()
|
||||
{
|
||||
@ -141,12 +141,3 @@ class CacheControllerTest extends TestCase
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class CacheConsoledController extends CacheController
|
||||
{
|
||||
|
||||
public function stdout($string)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
namespace yiiunit\framework\console\controllers;
|
||||
|
||||
use yii\console\controllers\MigrateController;
|
||||
|
||||
/**
|
||||
* MigrateController that writes output via echo instead of using output stream. Allows us to buffer it.
|
||||
*/
|
||||
class EchoMigrateController extends MigrateController
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function stdout($string)
|
||||
{
|
||||
echo $string;
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ class MigrateControllerTest extends TestCase
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->migrateControllerClass = MigrateController::className();
|
||||
$this->migrateControllerClass = EchoMigrateController::className();
|
||||
$this->migrationBaseClass = Migration::className();
|
||||
|
||||
$this->mockApplication([
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace yiiunit\framework\console\controllers;
|
||||
|
||||
|
||||
use yii\console\controllers\CacheController;
|
||||
|
||||
|
||||
/**
|
||||
* CacheController that discards output.
|
||||
*/
|
||||
class SilencedCacheController extends CacheController
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function stdout($string)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user