File tree Expand file tree Collapse file tree 3 files changed +17
-28
lines changed Expand file tree Collapse file tree 3 files changed +17
-28
lines changed Original file line number Diff line number Diff line change @@ -73,13 +73,11 @@ code. Use the :phpfunction:`array_replace` to fix that::
73
73
}
74
74
}
75
75
76
- Now all four options are guaranteed to be set. But what happens if the user of
77
- the ``Mailer `` class makes a mistake?
78
-
79
- .. code-block :: php
76
+ Now all four options are guaranteed to be set, but you could still make an error
77
+ like the following when using the ``Mailer `` class::
80
78
81
79
$mailer = new Mailer([
82
- 'usernme' => 'johndoe', // usernme misspelled (instead of username)
80
+ 'usernme' => 'johndoe', // 'username' is wrongly spelled as 'usernme'
83
81
]);
84
82
85
83
No error will be shown. In the best case, the bug will appear during testing,
Original file line number Diff line number Diff line change @@ -182,31 +182,22 @@ allows you to return a list of extensions to register::
182
182
namespace App\Tests\Form\Type;
183
183
184
184
// ...
185
- use App\Form\Type\TestedType;
186
185
use Symfony\Component\Form\Extension\Validator\ValidatorExtension;
187
- use Symfony\Component\Form\Form;
188
- use Symfony\Component\Validator\ConstraintViolationList;
189
- use Symfony\Component\Validator\Mapping\ClassMetadata;
190
- use Symfony\Component\Validator\Validator\ValidatorInterface;
186
+ use Symfony\Component\Validator\Validation;
191
187
192
188
class TestedTypeTest extends TypeTestCase
193
189
{
194
- private $validator;
195
-
196
190
protected function getExtensions()
197
191
{
198
- $this->validator = $this->createMock(ValidatorInterface::class);
199
- // use getMock() on PHPUnit 5.3 or below
200
- // $this->validator = $this->getMock(ValidatorInterface::class);
201
- $this->validator
202
- ->method('validate')
203
- ->will($this->returnValue(new ConstraintViolationList()));
204
- $this->validator
205
- ->method('getMetadataFor')
206
- ->will($this->returnValue(new ClassMetadata(Form::class)));
192
+ $validator = Validation::createValidator();
193
+
194
+ // or if you also need to read constraints from annotations
195
+ $validator = Validation::createValidatorBuilder()
196
+ ->enableAnnotationMapping()
197
+ ->getValidator();
207
198
208
199
return [
209
- new ValidatorExtension($this-> validator),
200
+ new ValidatorExtension($validator),
210
201
];
211
202
}
212
203
Original file line number Diff line number Diff line change @@ -212,12 +212,12 @@ get logged on the server as well as the emails being sent:
212
212
type : deduplication
213
213
handler : swift
214
214
swift :
215
- type : swift_mailer
216
- from_email : ' error@example.com'
217
- to_email : ' error@example.com'
218
- subject : ' An Error Occurred! %%message%%'
219
- level : debug
220
- formatter : monolog.formatter.html
215
+ type : swift_mailer
216
+ from_email : ' error@example.com'
217
+ to_email : ' error@example.com'
218
+ subject : ' An Error Occurred! %%message%%'
219
+ level : debug
220
+ formatter : monolog.formatter.html
221
221
content_type : text/html
222
222
223
223
.. code-block :: xml
You can’t perform that action at this time.
0 commit comments