Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow specifying "break chain on failure" flag as Validator option #5780

Merged
merged 2 commits into from

2 participants

@weierophinney
  • When calling attachByName(), allow passing the "break chain on failure"
    flag
    as an option, instead of requiring it to be passed as the third argument to
    the method; simplifies factories.

  • Fixes zfcampus/zf-apigility-admin#89

@weierophinney weierophinney Allow specifying "break chain on failure" flag as option
- When calling `attachByName()`, allow passing the "break chain on failure" flag
  as an option, instead of requiring it to be passed as the third argument to
  the method; simplifies factories.

- Fixes zfcampus/zf-apigility-admin#89
7dc83b5
@Maks3w Maks3w commented on the diff
library/Zend/Validator/ValidatorChain.php
@@ -146,6 +146,14 @@ public function prependValidator(ValidatorInterface $validator, $breakChainOnFai
*/
public function attachByName($name, $options = array(), $breakChainOnFailure = false)
{
+ if (isset($options['break_chain_on_failure'])) {
+ $breakChainOnFailure = (bool) $options['break_chain_on_failure'];
+ }
+
+ if (isset($options['breakchainonfailure'])) {
+ $breakChainOnFailure = (bool) $options['breakchainonfailure'];
@Maks3w Collaborator
Maks3w added a note

Sincerely I don't like to have different ways of write the same thing. IMO this is an overhead for the framework.

Anyway, If you consider this necessary please add a test case for this option too.

@weierophinney Owner

I'll add a test case -- mainly because it's documented both ways in different locations.

@Maks3w Collaborator
Maks3w added a note

For the record:
The uses of these config keys are in Zend/File/Transfer/Adapter/AbstractAdapter.php and Zend/InputFilter/Factory.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weierophinney weierophinney Ensure both flags are tested
- Wrote a data provider so that the option name both with and without
  underscores may be tested.
0e057af
@Maks3w Maks3w merged commit 95e1d90 into from
@weierophinney weierophinney deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 3, 2014
  1. @weierophinney

    Allow specifying "break chain on failure" flag as option

    weierophinney authored
    - When calling `attachByName()`, allow passing the "break chain on failure" flag
      as an option, instead of requiring it to be passed as the third argument to
      the method; simplifies factories.
    
    - Fixes zfcampus/zf-apigility-admin#89
  2. @weierophinney

    Ensure both flags are tested

    weierophinney authored
    - Wrote a data provider so that the option name both with and without
      underscores may be tested.
This page is out of date. Refresh to see the latest.
View
8 library/Zend/Validator/ValidatorChain.php
@@ -146,6 +146,14 @@ public function prependValidator(ValidatorInterface $validator, $breakChainOnFai
*/
public function attachByName($name, $options = array(), $breakChainOnFailure = false)
{
+ if (isset($options['break_chain_on_failure'])) {
+ $breakChainOnFailure = (bool) $options['break_chain_on_failure'];
+ }
+
+ if (isset($options['breakchainonfailure'])) {
+ $breakChainOnFailure = (bool) $options['breakchainonfailure'];
@Maks3w Collaborator
Maks3w added a note

Sincerely I don't like to have different ways of write the same thing. IMO this is an overhead for the framework.

Anyway, If you consider this necessary please add a test case for this option too.

@weierophinney Owner

I'll add a test case -- mainly because it's documented both ways in different locations.

@Maks3w Collaborator
Maks3w added a note

For the record:
The uses of these config keys are in Zend/File/Transfer/Adapter/AbstractAdapter.php and Zend/InputFilter/Factory.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ }
+
$validator = $this->plugin($name, $options);
$this->attach($validator, $breakChainOnFailure);
return $this;
View
30 tests/ZendTest/Validator/ValidatorChainTest.php
@@ -281,4 +281,34 @@ public function testCanSerializeValidatorChain()
$this->assertEquals(2, count($unserialized));
$this->assertFalse($unserialized->isValid(''));
}
+
+ public function breakChainFlags()
+ {
+ return array(
+ 'underscores' => array('break_chain_on_failure'),
+ 'no_underscores' => array('breakchainonfailure'),
+ );
+ }
+
+ /**
+ * @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']);
+ }
}
Something went wrong with that request. Please try again.