Exemplo n.º 1
0
 /**
  * @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);
 }
Exemplo n.º 2
0
 /**
  * @group zfcampus_zf-apigility-admin_89
  * @dataProvider breakChainFlags
  */
 public function testAttachByNameAllowsSpecifyingBreakChainOnFailureFlagViaOptions($option)
 {
     $this->validator->attachByName('GreaterThan', array($option => true, 'min' => 1));
     $this->assertEquals(1, count($this->validator));
     $validators = $this->validator->getValidators();
     $spec = array_shift($validators);
     $this->assertInternalType('array', $spec);
     $this->assertArrayHasKey('instance', $spec);
     $validator = $spec['instance'];
     $this->assertInstanceOf('Zend\\Validator\\GreaterThan', $validator);
     $this->assertArrayHasKey('breakChainOnFailure', $spec);
     $this->assertTrue($spec['breakChainOnFailure']);
 }