Skip to content

Commit 159f284

Browse files
committed
MAGETWO-63764: [TD] Fix exceptions in Scope/Validator
1 parent d7b0afe commit 159f284

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

lib/internal/Magento/Framework/App/Scope/Validator.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use InvalidArgumentException;
99
use Magento\Framework\App\Config\ScopeConfigInterface;
1010
use Magento\Framework\App\ScopeResolverPool;
11-
use Magento\Framework\Exception\LocalizedException;
1211
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\Exception\ValidatorException;
1313
use Magento\Framework\Phrase;
1414

1515
/**
@@ -40,14 +40,14 @@ public function isValid($scope, $scopeCode = null)
4040
}
4141

4242
if ($scope === ScopeConfigInterface::SCOPE_TYPE_DEFAULT && !empty($scopeCode)) {
43-
throw new LocalizedException(new Phrase(
43+
throw new ValidatorException(new Phrase(
4444
'The "%1" scope can\'t include a scope code. Try again without entering a scope code.',
4545
[ScopeConfigInterface::SCOPE_TYPE_DEFAULT]
4646
));
4747
}
4848

4949
if (empty($scope)) {
50-
throw new LocalizedException(new Phrase('Enter a scope before proceeding.'));
50+
throw new ValidatorException(new Phrase('Enter a scope before proceeding.'));
5151
}
5252

5353
$this->validateScopeCode($scopeCode);
@@ -56,9 +56,9 @@ public function isValid($scope, $scopeCode = null)
5656
$scopeResolver = $this->scopeResolverPool->get($scope);
5757
$scopeResolver->getScope($scopeCode)->getId();
5858
} catch (InvalidArgumentException $e) {
59-
throw new LocalizedException(new Phrase('The "%1" value doesn\'t exist. Enter another value.', [$scope]));
59+
throw new ValidatorException(new Phrase('The "%1" value doesn\'t exist. Enter another value.', [$scope]));
6060
} catch (NoSuchEntityException $e) {
61-
throw new LocalizedException(
61+
throw new ValidatorException(
6262
new Phrase('The "%1" value doesn\'t exist. Enter another value.', [$scopeCode])
6363
);
6464
}
@@ -72,16 +72,16 @@ public function isValid($scope, $scopeCode = null)
7272
*
7373
* @param string $scopeCode
7474
* @return void
75-
* @throws LocalizedException if scope code is empty or has a wrong format
75+
* @throws ValidatorException if scope code is empty or has a wrong format
7676
*/
7777
private function validateScopeCode($scopeCode)
7878
{
7979
if (empty($scopeCode)) {
80-
throw new LocalizedException(new Phrase('Enter a scope code before proceeding.'));
80+
throw new ValidatorException(new Phrase('Enter a scope code before proceeding.'));
8181
}
8282

8383
if (!preg_match('/^[a-z]+[a-z0-9_]*$/', $scopeCode)) {
84-
throw new LocalizedException(new Phrase(
84+
throw new ValidatorException(new Phrase(
8585
'The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores (_). '
8686
. 'Also, the first character must be a letter.'
8787
));

lib/internal/Magento/Framework/App/Test/Unit/Config/Scope/ValidatorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testIsValidDefault()
6363
}
6464

6565
/**
66-
* @expectedException \Magento\Framework\Exception\LocalizedException
66+
* @expectedException \Magento\Framework\Exception\ValidatorException
6767
* @expectedExceptionMessage The "default" scope can't include a scope code. Try again without entering a scope
6868
*/
6969
public function testNotEmptyScopeCodeForDefaultScope()
@@ -72,7 +72,7 @@ public function testNotEmptyScopeCodeForDefaultScope()
7272
}
7373

7474
/**
75-
* @expectedException \Magento\Framework\Exception\LocalizedException
75+
* @expectedException \Magento\Framework\Exception\ValidatorException
7676
* @expectedExceptionMessage Enter a scope before proceeding.
7777
*/
7878
public function testEmptyScope()
@@ -81,7 +81,7 @@ public function testEmptyScope()
8181
}
8282

8383
/**
84-
* @expectedException \Magento\Framework\Exception\LocalizedException
84+
* @expectedException \Magento\Framework\Exception\ValidatorException
8585
* @expectedExceptionMessage Enter a scope code before proceeding.
8686
*/
8787
public function testEmptyScopeCode()
@@ -90,7 +90,7 @@ public function testEmptyScopeCode()
9090
}
9191

9292
/**
93-
* @expectedException \Magento\Framework\Exception\LocalizedException
93+
* @expectedException \Magento\Framework\Exception\ValidatorException
9494
* @expectedExceptionMessage The scope code can include only lowercase letters (a-z), numbers (0-9) and underscores
9595
*/
9696
public function testWrongScopeCodeFormat()
@@ -99,7 +99,7 @@ public function testWrongScopeCodeFormat()
9999
}
100100

101101
/**
102-
* @expectedException \Magento\Framework\Exception\LocalizedException
102+
* @expectedException \Magento\Framework\Exception\ValidatorException
103103
* @expectedExceptionMessage The "not_default_scope" value doesn't exist. Enter another value.
104104
*/
105105
public function testScopeNotExist()
@@ -114,7 +114,7 @@ public function testScopeNotExist()
114114
}
115115

116116
/**
117-
* @expectedException \Magento\Framework\Exception\LocalizedException
117+
* @expectedException \Magento\Framework\Exception\ValidatorException
118118
* @expectedExceptionMessage The "not_exist_scope_code" value doesn't exist. Enter another value.
119119
*/
120120
public function testScopeCodeNotExist()

0 commit comments

Comments
 (0)