Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'weierophinney/hotfix/zf2-412'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ValidatorChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function isValid($value, $context = null)
}
$result = false;
$messages = $validator->getMessages();
$this->messages = array_merge($this->messages, $messages);
$this->messages = array_replace_recursive($this->messages, $messages);
if ($element['breakChainOnFailure']) {
break;
}
Expand Down
7 changes: 7 additions & 0 deletions src/ValidatorPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class ValidatorPluginManager extends AbstractPluginManager
'step' => 'Zend\Validator\Step',
);

/**
* Whether or not to share by default; default to false
*
* @var bool
*/
protected $shareByDefault = false;

/**
* Constructor
*
Expand Down
53 changes: 53 additions & 0 deletions test/ValidatorChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ class ValidatorChainTest extends \PHPUnit_Framework_TestCase

public function setUp()
{
AbstractValidator::setMessageLength(-1);
$this->validator = new ValidatorChain();
}

public function tearDown()
{
AbstractValidator::setMessageLength(-1);
}

public function populateValidatorChain()
{
$this->validator->addValidator(new NotEmpty());
Expand Down Expand Up @@ -220,4 +226,51 @@ public function getValidatorFalse()
->will($this->returnValue(array('error' => 'validation failed')));
return $validator;
}

/**
* @group ZF-412
*/
public function testCanAttachMultipleValidatorsOfTheSameTypeAsDiscreteInstances()
{
$this->validator->addByName('Callback', array(
'callback' => function ($value) {
return true;
},
'messages' => array(
'callbackValue' => 'This should not be seen in the messages',
),
));
$this->validator->addByName('Callback', array(
'callback' => function ($value) {
return false;
},
'messages' => array(
'callbackValue' => 'Second callback trapped',
),
));

$this->assertEquals(2, count($this->validator));
$validators = $this->validator->getValidators();
$compare = null;
foreach ($validators as $validator) {
$this->assertNotSame($compare, $validator);
$compare = $validator;
}

$this->assertFalse($this->validator->isValid('foo'));
$messages = $this->validator->getMessages();
$found = false;
$test = 'Second callback trapped';
foreach ($messages as $messageSet) {
if (is_string($messageSet) && $messageSet === $test) {
$found = true;
break;
}
if (is_array($messageSet) && in_array('Second callback trapped', $messageSet)) {
$found = true;
break;
}
}
$this->assertTrue($found);
}
}

0 comments on commit 8937705

Please sign in to comment.