"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/framework/console/ControllerTest.php" between
yii2-2.0.35.tar.gz and yii2-2.0.36.tar.gz

About: Yii 2 is a high-performance component-based PHP framework for developing large-scale Web applications (source).

ControllerTest.php  (yii2-2.0.35):ControllerTest.php  (yii2-2.0.36)
<?php <?php
/** /**
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yiiunit\framework\console; namespace yiiunit\framework\console;
use RuntimeException;
use yii\console\Exception;
use yiiunit\framework\console\stubs\DummyService;
use Yii; use Yii;
use yii\base\InlineAction;
use yii\base\Module; use yii\base\Module;
use yii\console\Application;
use yii\console\Request; use yii\console\Request;
use yii\helpers\Console; use yii\helpers\Console;
use yiiunit\TestCase; use yiiunit\TestCase;
/** /**
* @group console * @group console
*/ */
class ControllerTest extends TestCase class ControllerTest extends TestCase
{ {
/** @var FakeController */
private $controller;
protected function setUp() protected function setUp()
{ {
parent::setUp(); parent::setUp();
$this->mockApplication(); $this->mockApplication();
Yii::$app->controllerMap = [ Yii::$app->controllerMap = [
'fake' => 'yiiunit\framework\console\FakeController', 'fake' => 'yiiunit\framework\console\FakeController',
'fake_witout_output' => 'yiiunit\framework\console\FakeHelpControlle rWithoutOutput', 'fake_witout_output' => 'yiiunit\framework\console\FakeHelpControlle rWithoutOutput',
'help' => 'yiiunit\framework\console\FakeHelpController', 'help' => 'yiiunit\framework\console\FakeHelpController',
]; ];
} }
skipping to change at line 79 skipping to change at line 87
$this->assertEquals('from params', $fromParam); $this->assertEquals('from params', $fromParam);
$this->assertEquals('notdefault', $other); $this->assertEquals('notdefault', $other);
$params = ['avaliable']; $params = ['avaliable'];
$message = Yii::t('yii', 'Missing required arguments: {params}', ['param s' => implode(', ', ['missing'])]); $message = Yii::t('yii', 'Missing required arguments: {params}', ['param s' => implode(', ', ['missing'])]);
$this->expectException('yii\console\Exception'); $this->expectException('yii\console\Exception');
$this->expectExceptionMessage($message); $this->expectExceptionMessage($message);
$result = $controller->runAction('aksi3', $params); $result = $controller->runAction('aksi3', $params);
} }
public function testNullableInjectedActionParams()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new Application([
'id' => 'app',
'basePath' => __DIR__,
]));
$this->mockApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionNullableInjection');
$params = [];
$args = $this->controller->bindActionParams($injectionAction, $params);
$this->assertEquals(\Yii::$app->request, $args[0]);
$this->assertNull($args[1]);
}
public function testInjectionContainerException()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new Application([
'id' => 'app',
'basePath' => __DIR__,
]));
$this->mockApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionInjection');
$params = ['between' => 'test', 'after' => 'another', 'before' => 'test'
];
\Yii::$container->set(DummyService::className(), function() { throw new
\RuntimeException('uh oh'); });
$this->expectException(get_class(new RuntimeException()));
$this->expectExceptionMessage('uh oh');
$this->controller->bindActionParams($injectionAction, $params);
}
public function testUnknownInjection()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new Application([
'id' => 'app',
'basePath' => __DIR__,
]));
$this->mockApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionInjection');
$params = ['between' => 'test', 'after' => 'another', 'before' => 'test'
];
\Yii::$container->clear(DummyService::className());
$this->expectException(get_class(new Exception()));
$this->expectExceptionMessage('Could not load required service: dummySer
vice');
$this->controller->bindActionParams($injectionAction, $params);
}
public function testInjectedActionParams()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', new Application([
'id' => 'app',
'basePath' => __DIR__,
]));
$this->mockApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionInjection');
$params = ['between' => 'test', 'after' => 'another', 'before' => 'test'
];
\Yii::$container->set(DummyService::className(), DummyService::className
());
$args = $this->controller->bindActionParams($injectionAction, $params);
$this->assertEquals($params['before'], $args[0]);
$this->assertEquals(\Yii::$app->request, $args[1]);
$this->assertEquals('Component: yii\console\Request $request', \Yii::$ap
p->requestedParams['request']);
$this->assertEquals($params['between'], $args[2]);
$this->assertInstanceOf(DummyService::className(), $args[3]);
$this->assertEquals('Container DI: yiiunit\framework\console\stubs\Dummy
Service $dummyService', \Yii::$app->requestedParams['dummyService']);
$this->assertNull($args[4]);
$this->assertEquals('Unavailable service: post', \Yii::$app->requestedPa
rams['post']);
$this->assertEquals($params['after'], $args[5]);
}
public function testInjectedActionParamsFromModule()
{
if (PHP_VERSION_ID < 70100) {
$this->markTestSkipped('Can not be tested on PHP < 7.1');
return;
}
$module = new \yii\base\Module('fake', new Application([
'id' => 'app',
'basePath' => __DIR__,
]));
$module->set('yii\data\DataProviderInterface', [
'class' => \yii\data\ArrayDataProvider::className(),
]);
// Use the PHP71 controller for this test
$this->controller = new FakePhp71Controller('fake', $module);
$this->mockWebApplication(['controller' => $this->controller]);
$injectionAction = new InlineAction('injection', $this->controller, 'act
ionModuleServiceInjection');
$args = $this->controller->bindActionParams($injectionAction, []);
$this->assertInstanceOf(\yii\data\ArrayDataProvider::className(), $args[
0]);
$this->assertEquals('Module yii\base\Module DI: yii\data\DataProviderInt
erface $dataProvider', \Yii::$app->requestedParams['dataProvider']);
}
public function assertResponseStatus($status, $response) public function assertResponseStatus($status, $response)
{ {
$this->assertInstanceOf('yii\console\Response', $response); $this->assertInstanceOf('yii\console\Response', $response);
$this->assertSame($status, $response->exitStatus); $this->assertSame($status, $response->exitStatus);
} }
public function runRequest($route, $args = 0) public function runRequest($route, $args = 0)
{ {
$request = new Request(); $request = new Request();
$request->setParams(func_get_args()); $request->setParams(func_get_args());
 End of changes. 5 change blocks. 
0 lines changed or deleted 139 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)