Skip to content
Browse files

Merge branch 'hotfix/3480' into develop

Forward port #3480
  • Loading branch information...
2 parents c43eaed + 0e79cdd commit 33227e85a991b8c4823eadec62e7b945347df2b8 @weierophinney weierophinney committed
Showing with 17 additions and 17 deletions.
  1. +5 −13 library/Zend/Validator/EmailAddress.php
  2. +12 −4 tests/ZendTest/Validator/EmailAddressTest.php
View
18 library/Zend/Validator/EmailAddress.php
@@ -104,10 +104,6 @@ public function __construct($options = array())
$options = $temp;
}
- if (!array_key_exists('hostnameValidator', $options)) {
- $options['hostnameValidator'] = null;
- }
-
parent::__construct($options);
}
@@ -139,14 +135,14 @@ public function setMessage($messageString, $messageKey = null)
/**
* Returns the set hostname validator
*
+ * If was not previously set then lazy load a new one
+ *
* @return Hostname
*/
public function getHostnameValidator()
{
- if (!isset($this->options['hostnameValidator'])
- || !$this->options['hostnameValidator'] instanceof Hostname
- ) {
- $this->setHostnameValidator();
+ if (!isset($this->options['hostnameValidator'])) {
+ $this->options['hostnameValidator'] = new Hostname($this->getAllow());
}
return $this->options['hostnameValidator'];
@@ -158,10 +154,6 @@ public function getHostnameValidator()
*/
public function setHostnameValidator(Hostname $hostnameValidator = null)
{
- if (!$hostnameValidator) {
- $hostnameValidator = new Hostname($this->getAllow());
- }
-
$this->options['hostnameValidator'] = $hostnameValidator;
return $this;
@@ -186,7 +178,7 @@ public function getAllow()
public function setAllow($allow)
{
$this->options['allow'] = $allow;
- if ($this->options['hostnameValidator'] !== null) {
+ if (isset($this->options['hostnameValidator'])) {
$this->options['hostnameValidator']->setAllow($allow);
}
View
16 tests/ZendTest/Validator/EmailAddressTest.php
@@ -522,8 +522,12 @@ public function testSetSingleMessage()
public function testSetSingleMessageViaOptions()
{
$validator = new EmailAddress(array('message' => 'TestMessage'));
- $messages = $validator->getMessageTemplates();
- $this->assertEquals('TestMessage', $messages[EmailAddress::INVALID]);
+ foreach ($validator->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
+ foreach ($validator->getHostnameValidator()->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
}
public function testSetMultipleMessageViaOptions()
@@ -559,8 +563,12 @@ public function testSetMultipleMessages()
$messages = $this->validator->getMessageTemplates();
$this->assertNotEquals('TestMessage', $messages[EmailAddress::INVALID]);
$this->validator->setMessage('TestMessage');
- $messages = $this->validator->getMessageTemplates();
- $this->assertEquals('TestMessage', $messages[EmailAddress::INVALID]);
+ foreach ($this->validator->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
+ foreach ($this->validator->getHostnameValidator()->getMessageTemplates() as $message) {
+ $this->assertEquals('TestMessage', $message);
+ }
}
/**

0 comments on commit 33227e8

Please sign in to comment.
Something went wrong with that request. Please try again.