Skip to content

Commit

Permalink
Remove deprecated InvalidParamException::class in branch 2.2.
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Jul 17, 2023
1 parent c9c100a commit 2d744fc
Show file tree
Hide file tree
Showing 27 changed files with 44 additions and 72 deletions.
2 changes: 1 addition & 1 deletion framework/base/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @author Qiang Xue <[email protected]>
* @since 2.0.14
*/
class InvalidArgumentException extends InvalidParamException
class InvalidArgumentException extends \BadMethodCallException
{
/**
* @return string the user-friendly name of this exception
Expand Down
26 changes: 0 additions & 26 deletions framework/base/InvalidParamException.php

This file was deleted.

1 change: 0 additions & 1 deletion framework/classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
'yii\base\InvalidArgumentException' => YII2_PATH . '/base/InvalidArgumentException.php',
'yii\base\InvalidCallException' => YII2_PATH . '/base/InvalidCallException.php',
'yii\base\InvalidConfigException' => YII2_PATH . '/base/InvalidConfigException.php',
'yii\base\InvalidParamException' => YII2_PATH . '/base/InvalidParamException.php',
'yii\base\InvalidRouteException' => YII2_PATH . '/base/InvalidRouteException.php',
'yii\base\InvalidValueException' => YII2_PATH . '/base/InvalidValueException.php',
'yii\base\Model' => YII2_PATH . '/base/Model.php',
Expand Down
4 changes: 2 additions & 2 deletions framework/console/controllers/FixtureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace yii\console\controllers;

use Yii;
use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\console\Controller;
use yii\console\Exception;
use yii\console\ExitCode;
Expand Down Expand Up @@ -536,7 +536,7 @@ private function getFixturePath()
{
try {
return Yii::getAlias('@' . str_replace('\\', '/', $this->namespace));
} catch (InvalidParamException $e) {
} catch (InvalidArgumentException $e) {

Check warning on line 539 in framework/console/controllers/FixtureController.php

View check run for this annotation

Codecov / codecov/patch

framework/console/controllers/FixtureController.php#L539

Added line #L539 was not covered by tests
throw new InvalidConfigException('Invalid fixture namespace: "' . $this->namespace . '". Please, check your FixtureController::namespace parameter');
}
}
Expand Down
5 changes: 2 additions & 3 deletions framework/db/BaseActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use yii\base\InvalidArgumentException;
use yii\base\InvalidCallException;
use yii\base\InvalidConfigException;
use yii\base\InvalidParamException;
use yii\base\Model;
use yii\base\ModelEvent;
use yii\base\NotSupportedException;
Expand Down Expand Up @@ -1621,7 +1620,7 @@ public function getAttributeLabel($attribute)
} else {
try {
$relation = $relatedModel->getRelation($relationName);
} catch (InvalidParamException $e) {
} catch (InvalidArgumentException $e) {

Check warning on line 1623 in framework/db/BaseActiveRecord.php

View check run for this annotation

Codecov / codecov/patch

framework/db/BaseActiveRecord.php#L1623

Added line #L1623 was not covered by tests
return $this->generateAttributeLabel($attribute);
}
/* @var $modelClass ActiveRecordInterface */
Expand Down Expand Up @@ -1663,7 +1662,7 @@ public function getAttributeHint($attribute)
} else {
try {
$relation = $relatedModel->getRelation($relationName);
} catch (InvalidParamException $e) {
} catch (InvalidArgumentException $e) {

Check warning on line 1665 in framework/db/BaseActiveRecord.php

View check run for this annotation

Codecov / codecov/patch

framework/db/BaseActiveRecord.php#L1665

Added line #L1665 was not covered by tests
return '';
}
/* @var $modelClass ActiveRecordInterface */
Expand Down
4 changes: 2 additions & 2 deletions framework/db/conditions/ConditionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace yii\db\conditions;

use yii\base\InvalidParamException;
use InvalidArgumentException;
use yii\db\ExpressionInterface;

/**
Expand All @@ -27,7 +27,7 @@ interface ConditionInterface extends ExpressionInterface
* @param array $operands array of corresponding operands
*
* @return $this
* @throws InvalidParamException if input parameters are not suitable for this condition
* @throws InvalidArgumentException if input parameters are not suitable for this condition
*/
public static function fromArrayDefinition($operator, $operands);
}
2 changes: 1 addition & 1 deletion framework/rbac/CheckAccessInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface CheckAccessInterface
* @param array $params name-value pairs that will be passed to the rules associated
* with the roles and permissions assigned to the user.
* @return bool whether the user has the specified permission.
* @throws \yii\base\InvalidParamException if $permissionName does not refer to an existing permission
* @throws \yii\base\InvalidArgumentException if $permissionName does not refer to an existing permission
*/
public function checkAccess($userId, $permissionName, $params = []);
}
2 changes: 1 addition & 1 deletion framework/rbac/ManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function getRolesByUser($userId);
* @param string $roleName name of the role to file child roles for
* @return Role[] Child roles. The array is indexed by the role names.
* First element is an instance of the parent Role itself.
* @throws \yii\base\InvalidParamException if Role was not found that are getting by $roleName
* @throws \yii\base\InvalidArgumentException if Role was not found that are getting by $roleName
* @since 2.0.10
*/
public function getChildRoles($roleName);
Expand Down
2 changes: 1 addition & 1 deletion framework/web/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ public function argumentsToString($args)
*/
public function getExceptionName($exception)
{
if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidParamException || $exception instanceof \yii\base\UnknownMethodException) {
if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidArgumentException || $exception instanceof \yii\base\UnknownMethodException) {
return $exception->getName();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/framework/base/SecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ public function testUnMaskingInvalidStrings()

public function testMaskingInvalidStrings()
{
$this->expectException('\yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('First parameter ($length) must be greater than 0');

$this->security->maskToken('');
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/console/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static function provider(): array
],
[
// PHP does not allow variable name, starting with digit.
// InvalidParamException must be thrown during request resolving:
// InvalidArgumentException must be thrown during request resolving:
'params' => [
'controller/route',
'--0=test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ public function tearDown(): void
}

/**
* @throws \yii\base\InvalidParamException
* @throws \yii\db\Exception
* @throws \yii\base\InvalidConfigException
* @return \yii\db\Connection
* @throws \yii\base\InvalidArgumentException
* @throws \yii\base\InvalidConfigException
* @throws \yii\db\Exception
*/
public static function getConnection()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/db/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ public function testInsertSelectFailed(array|string $invalidSelectColumns): void
$db = $this->getConnection();
$command = $db->createCommand();

$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('Expected select query object with enumerated (named) parameters');

$command->insert('{{customer}}', $query)->execute();
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/db/GetTablesAliasTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function testGetTableNames_isFromAliasedExpression()
$expression = new \yii\db\Expression('(SELECT id FROM user)');
$query->from = $expression;

$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('To use Expression in from() method, pass it in array format with alias.');
$tables = $query->getTablesUsedInFrom();

Expand Down
12 changes: 6 additions & 6 deletions tests/framework/helpers/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,16 @@ public function testMultisortClosure()
], $changelog);
}

public function testMultisortInvalidParamExceptionDirection()
public function testMultisortInvalidArgumentExceptionDirection()
{
$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$data = ['foo' => 'bar'];
ArrayHelper::multisort($data, ['foo'], []);
}

public function testMultisortInvalidParamExceptionSortFlag()
public function testMultisortInvalidArgumentExceptionSortFlag()
{
$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$data = ['foo' => 'bar'];
ArrayHelper::multisort($data, ['foo'], ['foo'], []);
}
Expand Down Expand Up @@ -1243,7 +1243,7 @@ public function testIsInStrict()

public function testInException()
{
$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('Argument $haystack must be an array or implement Traversable');
ArrayHelper::isIn('value', null);
}
Expand All @@ -1262,7 +1262,7 @@ public function testIsSubset()

public function testIsSubsetException()
{
$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('Argument $needles must be an array or implement Traversable');
ArrayHelper::isSubset('a', new \ArrayObject(['a', 'b']));
}
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/helpers/FileHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function testCopyDirectoryToItself()
$dirName => [],
]);

$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);

$dirName = $this->testFilePath . DIRECTORY_SEPARATOR . 'test_dir';
FileHelper::copyDirectory($dirName, $dirName);
Expand All @@ -329,7 +329,7 @@ public function testCopyDirToSubdirOfItself()
'backup' => ['data' => []],
]);

$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);

FileHelper::copyDirectory(
$this->testFilePath . DIRECTORY_SEPARATOR . 'backup',
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/helpers/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function testDecode()
/**
* @covers ::decode
*/
public function testDecodeInvalidParamException()
public function testDecodeInvalidArgumentException()
{
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid JSON data.');
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/helpers/MarkdownTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public function testOriginalFlavor()
$this->assertEquals(Markdown::process($text), Markdown::process($text, 'gfm-comment'));
}

public function testProcessInvalidParamException()
public function testProcessInvalidArgumentException()
{
$this->expectException(\yii\base\InvalidParamException::class);
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage("Markdown flavor 'undefined' is not defined.");

Markdown::process('foo', 'undefined');
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/helpers/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testToRoute()
// In case there is no controller, an exception should be thrown for relative route
$this->removeMockedAction();

$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
Url::toRoute('site/view');
}

Expand Down Expand Up @@ -234,7 +234,7 @@ public function testTo()
//In case there is no controller, throw an exception
$this->removeMockedAction();

$this->expectException('yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
Url::to(['site/view']);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/framework/i18n/DbMessageSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ public static function tearDownAfterClass(): void
/**
* @return \yii\db\Connection
* @throws \yii\db\Exception
* @throws \yii\base\InvalidArgumentException
* @throws \yii\base\InvalidConfigException
* @throws \yii\base\InvalidParamException
*/
public static function getConnection()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/i18n/FormatterDateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function testFormat()
$this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'date'));
$this->assertSame(date('M j, Y', $value), $this->formatter->format($value, 'DATE'));
$this->assertSame(date('Y/m/d', $value), $this->formatter->format($value, ['date', 'php:Y/m/d']));
$this->expectException('\yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data'));
}

Expand Down Expand Up @@ -542,7 +542,7 @@ public static function dateInputs()
{
return [
['2015-01-01 00:00:00', '2014-13-01 00:00:00'],
[false, 'asdfg', 'yii\base\InvalidParamException'],
[false, 'asdfg', \yii\base\InvalidArgumentException::class],
// [(string)strtotime('now'), 'now'], // fails randomly
];
}
Expand Down
4 changes: 2 additions & 2 deletions tests/framework/i18n/FormatterNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ public function testIntlAsIntegerOptions()

public function testAsIntegerException()
{
$this->expectException('\yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->formatter->asInteger('a');
}

public function testAsIntegerException2()
{
$this->expectException('\yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->formatter->asInteger('-123abc');
}

Expand Down
10 changes: 5 additions & 5 deletions tests/framework/i18n/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ public function testFormat()
public function testInvalidFormat()
{
$value = time();
$this->expectException('\yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown format type: data');
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, 'data'));
}

public function testInvalidFormatArray()
{
$value = time();
$this->expectException('\yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('Unknown format type: data');
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, ['data']));
}

public function testFormatArrayInvalidStructure()
{
$value = time();
$this->expectException('\yii\base\InvalidParamException');
$this->expectException(\yii\base\InvalidArgumentException::class);
$this->expectExceptionMessage('The $format array must contain at least one element.');
$this->assertSame(date('Y-m-d', $value), $this->formatter->format($value, []));
}
Expand Down Expand Up @@ -358,7 +358,7 @@ public static function lengthDataProvider()
[
'Wrong value is casted properly',
['NaN'], '0 millimeters', '0 mm',
['yii\base\InvalidParamException', "'NaN' is not a numeric value"],
[\yii\base\InvalidArgumentException::class, "'NaN' is not a numeric value"],
],
[
'Negative value works',
Expand Down Expand Up @@ -457,7 +457,7 @@ public static function weightDataProvider()
[
'Wrong value is casted properly',
['NaN'], '0 grams', '0 g',
['yii\base\InvalidParamException', "'NaN' is not a numeric value"],
[\yii\base\InvalidArgumentException::class, "'NaN' is not a numeric value"],
],
[
'Negative value works',
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/log/DbTargetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public function tearDown(): void
}

/**
* @throws \yii\base\InvalidParamException
* @throws \yii\db\Exception
* @throws \yii\base\InvalidArgumentException
* @throws \yii\base\InvalidConfigException
* @return \yii\db\Connection
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/rbac/DbManagerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ protected function tearDown(): void
}

/**
* @throws \yii\base\InvalidParamException
* @throws \yii\db\Exception
* @throws \yii\base\InvalidArgumentException
* @throws \yii\base\InvalidConfigException
* @return \yii\db\Connection
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/framework/rbac/ManagerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace yiiunit\framework\rbac;

use yii\base\InvalidParamException;
use yii\base\InvalidArgumentException;
use yii\rbac\BaseManager;
use yii\rbac\Item;
use yii\rbac\Permission;
Expand Down
Loading

0 comments on commit 2d744fc

Please sign in to comment.