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

Commit

Permalink
Merge pull request zendframework/zendframework#6912 from Ocramius/hot…
Browse files Browse the repository at this point in the history
…fix/zendframework/zendframework#6386-zendframework/zendframework#6496-validator-chain-merge-type-mismatch

Hotfix: zendframework/zendframework#6386 zendframework/zendframework#6496 validator chain merge type mismatch
  • Loading branch information
Ocramius committed Nov 22, 2014
5 parents 9b5e8eb + a2ceda7 + 03ec649 + 70cd8e8 + 9ba3524 commit 34571c8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ValidatorChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function isValid($value, $context = null)
public function merge(ValidatorChain $validatorChain)
{
foreach ($validatorChain->validators->toArray(PriorityQueue::EXTR_BOTH) as $item) {
$this->attach($item['data'], $item['priority']);
$this->attach($item['data']['instance'], $item['data']['breakChainOnFailure'], $item['priority']);
}

return $this;
Expand Down Expand Up @@ -299,6 +299,14 @@ public function __invoke($value)
return $this->isValid($value);
}

/**
* Deep clone handling
*/
public function __clone()
{
$this->validators = clone $this->validators;
}

/**
* Prepare validator chain for serialization
*
Expand Down
36 changes: 36 additions & 0 deletions test/ValidatorChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,42 @@ public function testPrependValidatorsAreExecutedAccordingToPriority()
$this->assertArrayHasKey('error', $messages);
}

/**
* @group 6386
* @group 6496
*/
public function testMergeValidatorChains()
{
$mergedValidatorChain = new ValidatorChain();

$mergedValidatorChain->attach($this->getValidatorTrue());
$this->validator->attach($this->getValidatorTrue());

$this->validator->merge($mergedValidatorChain);

$this->assertCount(2, $this->validator->getValidators());
}

/**
* @group 6386
* @group 6496
*/
public function testValidatorChainIsCloneable()
{
$this->validator->attach(new NotEmpty());

$this->assertCount(1, $this->validator->getValidators());

$clonedValidatorChain = clone $this->validator;

$this->assertCount(1, $clonedValidatorChain->getValidators());

$clonedValidatorChain->attach(new NotEmpty());

$this->assertCount(1, $this->validator->getValidators());
$this->assertCount(2, $clonedValidatorChain->getValidators());
}

public function testCountGivesCountOfAttachedValidators()
{
$this->populateValidatorChain();
Expand Down

0 comments on commit 34571c8

Please sign in to comment.