@@ -12,13 +12,21 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
12
12
/** @var \Magento\Framework\Url\Validator */
13
13
protected $ object ;
14
14
15
+ /** @var \Zend\Validator\Uri */
16
+ protected $ zendValidator ;
17
+
15
18
/** @var string[] */
16
19
protected $ expectedValidationMessages = ['invalidUrl ' => "Invalid URL '%value%'. " ];
17
20
18
21
protected function setUp ()
19
22
{
20
23
$ objectManager = new ObjectManager ($ this );
21
- $ this ->object = $ objectManager ->getObject (\Magento \Framework \Url \Validator::class);
24
+
25
+ $ this ->zendValidator = $ this ->createMock (\Zend \Validator \Uri::class);
26
+ $ this ->object = $ objectManager ->getObject (
27
+ \Magento \Framework \Url \Validator::class,
28
+ ['validator ' => $ this ->zendValidator ]
29
+ );
22
30
}
23
31
24
32
public function testConstruct ()
@@ -28,13 +36,23 @@ public function testConstruct()
28
36
29
37
public function testIsValidWhenValid ()
30
38
{
31
- $ this ->assertEquals (true , $ this ->object ->isValid ('http://example.com ' ));
39
+ $ this ->zendValidator
40
+ ->method ('isValid ' )
41
+ ->with ('http://example.com ' )
42
+ ->willReturn (true );
43
+
44
+ $ this ->assertTrue ($ this ->object ->isValid ('http://example.com ' ));
32
45
$ this ->assertEquals ([], $ this ->object ->getMessages ());
33
46
}
34
47
35
48
public function testIsValidWhenInvalid ()
36
49
{
37
- $ this ->assertEquals (false , $ this ->object ->isValid ('%value% ' ));
50
+ $ this ->zendValidator
51
+ ->method ('isValid ' )
52
+ ->with ('%value% ' )
53
+ ->willReturn (false );
54
+
55
+ $ this ->assertFalse ($ this ->object ->isValid ('%value% ' ));
38
56
$ this ->assertEquals ($ this ->expectedValidationMessages , $ this ->object ->getMessages ());
39
57
}
40
58
}
0 commit comments