9 use \Magento\Framework\Exception\InputException;
22 $params = [
'fieldName' =>
'quantity',
'value' => -100,
'minValue' => 0];
24 new Phrase(
'The %fieldName value of "%value" must be greater than or equal to %minValue.',
$params)
28 'The %fieldName value of "%value" must be greater than or equal to %minValue.',
29 $inputException->getRawMessage()
31 $this->assertStringMatchesFormat(
'%s greater than or equal to %s', $inputException->getMessage());
33 'The quantity value of "-100" must be greater than or equal to 0.',
34 $inputException->getLogMessage()
47 $this->assertEquals(
'One or more input exceptions have occurred.', $inputException->getRawMessage());
49 'One or more input exceptions have occurred.',
50 $inputException->getMessage()
52 $this->assertEquals(
'One or more input exceptions have occurred.', $inputException->getLogMessage());
54 $this->assertFalse($inputException->wasErrorAdded());
55 $this->assertCount(0, $inputException->getErrors());
57 $inputException->addError(
59 'The %fieldName value of "%value" must be greater than or equal to %minValue.',
60 [
'fieldName' =>
'weight',
'value' => -100,
'minValue' => 1]
63 $this->assertTrue($inputException->wasErrorAdded());
64 $this->assertCount(0, $inputException->getErrors());
67 'The %fieldName value of "%value" must be greater than or equal to %minValue.',
68 $inputException->getRawMessage()
71 'The weight value of "-100" must be greater than or equal to 1.',
72 $inputException->getMessage()
75 'The weight value of "-100" must be greater than or equal to 1.',
76 $inputException->getLogMessage()
79 $inputException->addError(
80 new Phrase(
'"%fieldName" is required. Enter and try again.', [
'fieldName' =>
'name'])
82 $this->assertTrue($inputException->wasErrorAdded());
83 $this->assertCount(2, $inputException->getErrors());
85 $this->assertEquals(
'One or more input exceptions have occurred.', $inputException->getRawMessage());
87 'One or more input exceptions have occurred.',
88 $inputException->getMessage()
90 $this->assertEquals(
'One or more input exceptions have occurred.', $inputException->getLogMessage());
92 $errors = $inputException->getErrors();
96 'The %fieldName value of "%value" must be greater than or equal to %minValue.',
100 'The weight value of "-100" must be greater than or equal to 1.',
104 'The weight value of "-100" must be greater than or equal to 1.',
108 $this->assertEquals(
'"%fieldName" is required. Enter and try again.',
$errors[1]->getRawMessage());
109 $this->assertEquals(
'"name" is required. Enter and try again.',
$errors[1]->getMessage());
110 $this->assertEquals(
'"name" is required. Enter and try again.',
$errors[1]->getLogMessage());
120 $rawMessage =
'Foo "%var"';
122 $expectedProcessedMessage =
'Foo "Bar"';
124 $this->assertEquals($rawMessage, $inputException->getRawMessage());
125 $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
126 $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
127 $this->assertFalse($inputException->wasErrorAdded());
128 $this->assertCount(0, $inputException->getErrors());
131 $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
132 $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
133 $this->assertTrue($inputException->wasErrorAdded());
134 $this->assertCount(0, $inputException->getErrors());
137 $this->assertEquals($expectedProcessedMessage, $inputException->getMessage());
138 $this->assertEquals($expectedProcessedMessage, $inputException->getLogMessage());
139 $this->assertTrue($inputException->wasErrorAdded());
141 $errors = $inputException->getErrors();
142 $this->assertCount(2,
$errors);
143 $this->assertEquals($expectedProcessedMessage,
$errors[0]->getMessage());
144 $this->assertEquals($expectedProcessedMessage,
$errors[0]->getLogMessage());
145 $this->assertEquals($expectedProcessedMessage,
$errors[1]->getMessage());
146 $this->assertEquals($expectedProcessedMessage,
$errors[1]->getLogMessage());
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]