Browse Source

fix code to match 2.1

tags/3.0.0-alpha1
Klimov Paul 7 years ago
parent
commit
a39d1209ad
  1. 6
      docs/guide/db-active-record.md
  2. 2
      framework/db/QueryBuilder.php
  3. 2
      tests/framework/console/ControllerTest.php
  4. 6
      tests/framework/filters/auth/AuthTest.php
  5. 4
      tests/framework/helpers/FileHelperTest.php
  6. 2
      tests/framework/rest/UrlRuleTest.php
  7. 24
      tests/framework/web/RequestTest.php
  8. 2
      tests/framework/web/UrlRuleTest.php

6
docs/guide/db-active-record.md

@ -952,21 +952,21 @@ class Customer extends ActiveRecord
public function getPurchasedItems() public function getPurchasedItems()
{ {
// customer's items, matching 'id' column of `Item` to 'item_id' in OrderItem // customer's items, matching 'id' column of `Item` to 'item_id' in OrderItem
return $this->hasMany(Item::className(), ['id' => 'item_id']) return $this->hasMany(Item::class, ['id' => 'item_id'])
->via('orderItems'); ->via('orderItems');
} }
public function getOrderItems() public function getOrderItems()
{ {
// customer's order items, matching 'id' column of `Order` to 'order_id' in OrderItem // customer's order items, matching 'id' column of `Order` to 'order_id' in OrderItem
return $this->hasMany(OrderItem::className(), ['order_id' => 'id']) return $this->hasMany(OrderItem::class, ['order_id' => 'id'])
->via('orders'); ->via('orders');
} }
public function getOrders() public function getOrders()
{ {
// same as above // same as above
return $this->hasMany(Order::className(), ['customer_id' => 'id']); return $this->hasMany(Order::class, ['customer_id' => 'id']);
} }
} }
``` ```

2
framework/db/QueryBuilder.php

@ -799,7 +799,7 @@ class QueryBuilder extends \yii\base\BaseObject
public function createView($viewName, $subQuery) public function createView($viewName, $subQuery)
{ {
if ($subQuery instanceof Query) { if ($subQuery instanceof Query) {
list($rawQuery, $params) = $this->build($subQuery); [$rawQuery, $params] = $this->build($subQuery);
array_walk( array_walk(
$params, $params,
function(&$param) { function(&$param) {

2
tests/framework/console/ControllerTest.php

@ -63,7 +63,7 @@ class ControllerTest extends TestCase
$this->assertEquals('notdefault', $other); $this->assertEquals('notdefault', $other);
$params = ['test-array' => 'from params,notdefault']; $params = ['test-array' => 'from params,notdefault'];
list($fromParam, $other) = $controller->runAction('aksi6', $params); [$fromParam, $other] = $controller->runAction('aksi6', $params);
$this->assertEquals('from params', $fromParam); $this->assertEquals('from params', $fromParam);
$this->assertEquals('notdefault', $other); $this->assertEquals('notdefault', $other);

6
tests/framework/filters/auth/AuthTest.php

@ -238,15 +238,15 @@ class AuthTest extends \yiiunit\TestCase
public function testHeaders() public function testHeaders()
{ {
Yii::$app->request->headers->set('Authorization', "Bearer wrong_token"); Yii::$app->request->setHeader('Authorization', "Bearer wrong_token");
$filter = ['class' => HttpBearerAuth::className()]; $filter = ['class' => HttpBearerAuth::class];
$controller = Yii::$app->createController('test-auth')[0]; $controller = Yii::$app->createController('test-auth')[0];
$controller->authenticatorConfig = ArrayHelper::merge($filter, ['only' => ['filtered']]); $controller->authenticatorConfig = ArrayHelper::merge($filter, ['only' => ['filtered']]);
try { try {
$controller->run('filtered'); $controller->run('filtered');
$this->fail('Should throw UnauthorizedHttpException'); $this->fail('Should throw UnauthorizedHttpException');
} catch (UnauthorizedHttpException $e) { } catch (UnauthorizedHttpException $e) {
$this->assertArrayHasKey('WWW-Authenticate', Yii::$app->getResponse()->getHeaders()); $this->assertTrue(Yii::$app->getResponse()->hasHeader('www-authenticate'));
} }
} }
} }

4
tests/framework/helpers/FileHelperTest.php

@ -835,7 +835,7 @@ class FileHelperTest extends TestCase
*/ */
public function testCopyDirectoryEmptyDirectories() public function testCopyDirectoryEmptyDirectories()
{ {
list($basePath, $srcDirName) = $this->setupCopyEmptyDirectoriesTest(); [$basePath, $srcDirName] = $this->setupCopyEmptyDirectoriesTest();
// copy with empty directories // copy with empty directories
$dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_empty_dst_dir'; $dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_empty_dst_dir';
@ -860,7 +860,7 @@ class FileHelperTest extends TestCase
*/ */
public function testCopyDirectoryNoEmptyDirectories() public function testCopyDirectoryNoEmptyDirectories()
{ {
list($basePath, $srcDirName) = $this->setupCopyEmptyDirectoriesTest(); [$basePath, $srcDirName] = $this->setupCopyEmptyDirectoriesTest();
// copy without empty directories // copy without empty directories
$dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_empty_dst_dir2'; $dstDirName = $basePath . DIRECTORY_SEPARATOR . 'test_empty_dst_dir2';

2
tests/framework/rest/UrlRuleTest.php

@ -370,7 +370,7 @@ class UrlRuleTest extends TestCase
public function testGetCreateUrlStatus($ruleConfig, $tests) public function testGetCreateUrlStatus($ruleConfig, $tests)
{ {
foreach ($tests as $test) { foreach ($tests as $test) {
list($params, $expected, $status) = $test; [$params, $expected, $status] = $test;
$this->mockWebApplication(); $this->mockWebApplication();
Yii::$app->set('request', new Request(['hostInfo' => 'http://api.example.com', 'scriptUrl' => '/index.php'])); Yii::$app->set('request', new Request(['hostInfo' => 'http://api.example.com', 'scriptUrl' => '/index.php']));

24
tests/framework/web/RequestTest.php

@ -603,7 +603,7 @@ class RequestTest extends TestCase
public function testHttpAuthCredentialsFromServerSuperglobal() public function testHttpAuthCredentialsFromServerSuperglobal()
{ {
$original = $_SERVER; $original = $_SERVER;
list($user, $pw) = ['foo', 'bar']; [$user, $pw] = ['foo', 'bar'];
$_SERVER['PHP_AUTH_USER'] = $user; $_SERVER['PHP_AUTH_USER'] = $user;
$_SERVER['PHP_AUTH_PW'] = $pw; $_SERVER['PHP_AUTH_PW'] = $pw;
@ -900,27 +900,27 @@ class RequestTest extends TestCase
$this->assertSame(['attr2' => '2'], $newStorage->getAttributes()); $this->assertSame(['attr2' => '2'], $newStorage->getAttributes());
} }
public function testGetBodyParam() public function testGetParsedBodyParam()
{ {
$request = new Request(); $request = new Request();
$request->setBodyParams([ $request->setParsedBody([
'someParam' => 'some value', 'someParam' => 'some value',
'param.dot' => 'value.dot', 'param.dot' => 'value.dot',
]); ]);
$this->assertSame('some value', $request->getBodyParam('someParam')); $this->assertSame('some value', $request->getParsedBodyParam('someParam'));
$this->assertSame('value.dot', $request->getBodyParam('param.dot')); $this->assertSame('value.dot', $request->getParsedBodyParam('param.dot'));
$this->assertSame(null, $request->getBodyParam('unexisting')); $this->assertSame(null, $request->getParsedBodyParam('unexisting'));
$this->assertSame('default', $request->getBodyParam('unexisting', 'default')); $this->assertSame('default', $request->getParsedBodyParam('unexisting', 'default'));
// @see https://github.com/yiisoft/yii2/issues/14135 // @see https://github.com/yiisoft/yii2/issues/14135
$bodyParams = new \stdClass(); $bodyParams = new \stdClass();
$bodyParams->someParam = 'some value'; $bodyParams->someParam = 'some value';
$bodyParams->{'param.dot'} = 'value.dot'; $bodyParams->{'param.dot'} = 'value.dot';
$request->setBodyParams($bodyParams); $request->setParsedBody($bodyParams);
$this->assertSame('some value', $request->getBodyParam('someParam')); $this->assertSame('some value', $request->getParsedBodyParam('someParam'));
$this->assertSame('value.dot', $request->getBodyParam('param.dot')); $this->assertSame('value.dot', $request->getParsedBodyParam('param.dot'));
$this->assertSame(null, $request->getBodyParam('unexisting')); $this->assertSame(null, $request->getParsedBodyParam('unexisting'));
$this->assertSame('default', $request->getBodyParam('unexisting', 'default')); $this->assertSame('default', $request->getParsedBodyParam('unexisting', 'default'));
} }
} }

2
tests/framework/web/UrlRuleTest.php

@ -1286,7 +1286,7 @@ class UrlRuleTest extends TestCase
public function testGetCreateUrlStatus($config, $tests) public function testGetCreateUrlStatus($config, $tests)
{ {
foreach ($tests as $test) { foreach ($tests as $test) {
list($route, $params, $expected, $status) = $test; [$route, $params, $expected, $status] = $test;
$this->mockWebApplication(); $this->mockWebApplication();
Yii::$app->set('request', new Request(['hostInfo' => 'http://example.com', 'scriptUrl' => '/index.php'])); Yii::$app->set('request', new Request(['hostInfo' => 'http://example.com', 'scriptUrl' => '/index.php']));

Loading…
Cancel
Save