File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 11
11
12
12
namespace Symfony \Component \Validator \Tests \Constraints ;
13
13
14
+ use Symfony \Bridge \PhpUnit \DnsMock ;
14
15
use Symfony \Component \Validator \Constraints \Email ;
15
16
use Symfony \Component \Validator \Constraints \EmailValidator ;
16
17
18
+ /**
19
+ * @group dns-sensitive
20
+ */
17
21
class EmailValidatorTest extends AbstractConstraintValidatorTest
18
22
{
19
23
protected function createValidator ()
@@ -86,4 +90,39 @@ public function getInvalidEmails()
86
90
array ('example@localhost ' ),
87
91
);
88
92
}
93
+
94
+ /**
95
+ * @dataProvider getDnsChecks
96
+ */
97
+ public function testDnsChecks ($ type , $ violation )
98
+ {
99
+ DnsMock::withMockedHosts (array ('example.com ' => array (array ('type ' => $ violation ? false : $ type ))));
100
+
101
+ $ constraint = new Email (array (
102
+ 'message ' => 'myMessage ' ,
103
+ 'MX ' === $ type ? 'checkMX ' : 'checkHost ' => true ,
104
+ ));
105
+
106
+ $ this ->
validator ->
validate (
'[email protected] ' ,
$ constraint);
107
+
108
+ if (!$ violation ) {
109
+ $ this ->assertNoViolation ();
110
+ } else {
111
+ $ this ->buildViolation ('myMessage ' )
112
+ ->
setParameter (
'{{ value }} ' ,
'"[email protected] " ' )
113
+ ->assertRaised ();
114
+ }
115
+ }
116
+
117
+ public function getDnsChecks ()
118
+ {
119
+ return array (
120
+ array ('MX ' , false ),
121
+ array ('MX ' , true ),
122
+ array ('A ' , false ),
123
+ array ('A ' , true ),
124
+ array ('AAAA ' , false ),
125
+ array ('AAAA ' , true ),
126
+ );
127
+ }
89
128
}
You can’t perform that action at this time.
0 commit comments