From ed82ba4ee24497905c72d408705bc9227e4272cd Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Tue, 20 Dec 2016 12:39:25 +0200 Subject: [PATCH] Revert "fix ArrayHelper::getValue() to throw exception on invalid input" This reverts commit e963b2af6486dd79c26a460148c63efb580f53fc because of BC breaking reported in #13248. To know more about the reasons of commit revertinvg, visit https://github.com/yiisoft/yii2/issues/13248 --- framework/CHANGELOG.md | 1 - framework/helpers/BaseArrayHelper.php | 7 +---- tests/framework/helpers/ArrayHelperTest.php | 31 --------------------- 3 files changed, 1 insertion(+), 38 deletions(-) diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 23ed653c49..bacb623b52 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -27,7 +27,6 @@ Yii Framework 2 Change Log - Bug #12879: Console progress bar was not working properly in Windows terminals (samdark, kids-return) - Bug #12880: Fixed `yii\behaviors\AttributeTypecastBehavior` marks attributes with `null` value as 'dirty' (klimov-paul) - Bug #12904: Fixed lowercase table name in migrations (zlakomanoff) -- Bug #12927: `ArrayHelper::getValue()` did not throw exception if the input was neither an object nor an array, even though it was documented (cebe) - Bug #12939: Hard coded table names for MSSQL in RBAC migration (arogachev) - Bug #12974: Fixed incorrect order of migrations history in case `yii\console\controllers\MigrateController::$migrationNamespaces` is in use (evgen-d, klimov-paul) - Bug #13071: Help option for commands was not working in modules (arogachev, haimanman) diff --git a/framework/helpers/BaseArrayHelper.php b/framework/helpers/BaseArrayHelper.php index e545a0a50f..a395f6fb16 100644 --- a/framework/helpers/BaseArrayHelper.php +++ b/framework/helpers/BaseArrayHelper.php @@ -178,15 +178,10 @@ class BaseArrayHelper * The possibility to pass an array of keys is available since version 2.0.4. * @param mixed $default the default value to be returned if the specified array key does not exist. Not used when * getting value from an object. - * @return mixed the value of the element if found, default value otherwise. - * @throws InvalidParamException if $array is neither an array nor an object. + * @return mixed the value of the element if found, default value otherwise */ public static function getValue($array, $key, $default = null) { - if (!is_array($array) && !is_object($array)) { - throw new InvalidParamException('Argument passed to getValue() must be an array or object.'); - } - if ($key instanceof \Closure) { return $key($array, $default); } diff --git a/tests/framework/helpers/ArrayHelperTest.php b/tests/framework/helpers/ArrayHelperTest.php index 9c5d2231bc..ac02760001 100644 --- a/tests/framework/helpers/ArrayHelperTest.php +++ b/tests/framework/helpers/ArrayHelperTest.php @@ -2,7 +2,6 @@ namespace yiiunit\framework\helpers; -use yii\base\InvalidParamException; use yii\base\Object; use yii\helpers\ArrayHelper; use yiiunit\TestCase; @@ -735,36 +734,6 @@ class ArrayHelperTest extends TestCase $this->assertEquals(23, ArrayHelper::getValue($arrayObject, 'nonExisting')); } - public function invalidArgumentProvider() - { - return [ - [null], - [false], - [true], - [42], - [''], - ['not an object'], - ]; - } - - /** - * @dataProvider invalidArgumentProvider - * @expectedException \yii\base\InvalidParamException - */ - public function testGetValueInvalidArgumentWithoutDefaultValue($arg) - { - ArrayHelper::getValue($arg, 'test'); - } - - /** - * @dataProvider invalidArgumentProvider - * @expectedException \yii\base\InvalidParamException - */ - public function testGetValueInvalidArgumentWithDefaultValue($arg) - { - ArrayHelper::getValue($arg, 'test', 'default'); - } - public function testIsAssociative() { $this->assertFalse(ArrayHelper::isAssociative('test'));