/** * @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); }
protected function populateValidators(ValidatorChain $chain, $validators) { foreach ($validators as $validator) { if ($validator instanceof ValidatorInterface) { $chain->addValidator($validator); continue; } if (is_array($validator)) { if (!isset($validator['name'])) { throw new Exception\RuntimeException('Invalid validator specification provided; does not include "name" key'); } $name = $validator['name']; $options = array(); if (isset($validator['options'])) { $options = $validator['options']; } $breakChainOnFailure = false; if (isset($validator['break_chain_on_failure'])) { $breakChainOnFailure = $validator['break_chain_on_failure']; } $chain->addByName($name, $options, $breakChainOnFailure); continue; } throw new Exception\RuntimeException('Invalid validator specification provided; was neither a validator instance nor an array specification'); } }