Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit b8425c5

Browse files
author
Ben Batschelet
committed
Fix Url Validator unit tests
1 parent a7a1df0 commit b8425c5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

lib/internal/Magento/Framework/Url/Test/Unit/ValidatorTest.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
1212
/** @var \Magento\Framework\Url\Validator */
1313
protected $object;
1414

15+
/** @var \Zend\Validator\Uri */
16+
protected $zendValidator;
17+
1518
/** @var string[] */
1619
protected $expectedValidationMessages = ['invalidUrl' => "Invalid URL '%value%'."];
1720

1821
protected function setUp()
1922
{
2023
$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+
);
2230
}
2331

2432
public function testConstruct()
@@ -28,13 +36,23 @@ public function testConstruct()
2836

2937
public function testIsValidWhenValid()
3038
{
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'));
3245
$this->assertEquals([], $this->object->getMessages());
3346
}
3447

3548
public function testIsValidWhenInvalid()
3649
{
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%'));
3856
$this->assertEquals($this->expectedValidationMessages, $this->object->getMessages());
3957
}
4058
}

0 commit comments

Comments
 (0)