Skip to content

Commit

Permalink
Backported 2.5.5 fixes to 2.4 series
Browse files Browse the repository at this point in the history
Includes these changes:

- [14: NotEmpty validator doesn't override the required attribute](zendframework#14)
- [16: BC in validators context value](zendframework#16)
- [24: Fix loop validation input context is mutable](zendframework#24)
- [25: Fix missing optional fields should not be validated](zendframework#25)
- [26: Deprecate magic logic for auto attaching a NonEmpty validator with breakChainOnFailure = true](zendframework#26)
- [31: Update the InputFilterInterface::add docblock to match existing, shipped implementations](zendframework#31)
- [36: Fix docblocks declared as regular comment block](zendframework#36)
- [40: Remove test about Input setters permutation](zendframework#40)
- [41: Refactor tests for group 7448 as a data set matrix](zendframework#41)
- [42: Consolidate InputFilterPluginManager tests](zendframework#42)
- [43: Consolidate Factory tests + Fixes](zendframework#43)
- [44: Consolidate of InputInterface::merge and Fix unsafe merge](zendframework#44)
- [45: When merge Inputs don't merge values if source does not have one.](zendframework#45)
- [46: Expand test matrix with nonempty value scenarios](zendframework#46)
- [47: Feature/minor test improvements](zendframework#47)
- [48: Empty values + Allow Empty + Not continue if empty is always true](zendframework#48)
- [49: Add tests for exceptions and improve some messages](zendframework#49)
- [50: Optional fields without value should be valid ](zendframework#50)
- [51: Optional input without value are valid](zendframework#51)
- [52: Fix merge two inputs without value, result 'has value' flag should be false](zendframework#52)
- [56: Hotfix/minor changes](zendframework#56)
- [57: Consolidate tests for InputFilterInterface](zendframework#57)
- [61: Provide NotEmpty::IS&zendframework#95;EMPTY validation message for required input](zendframework#61)
- [63: Ensure custom error messages are used for required missing inputs](zendframework#63)
- [64: Feature/test cleanup](zendframework#64)
  • Loading branch information
weierophinney committed Sep 9, 2015
1 parent 3a37474 commit aa16fb2
Show file tree
Hide file tree
Showing 32 changed files with 2,647 additions and 2,707 deletions.
24 changes: 24 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
root = true

[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true

[**.php]
indent_size = 4
continuation_indent_size = 4
insert_final_newline = true

[**.xml]
indent_size = 4

[**.yml]
indent_size = 2

[composer.json]
indent_size = 4

[package.json]
indent_size = 2
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/test export-ignore
/vendor export-ignore
.coveralls.yml export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
.php_cs export-ignore
phpunit.xml.dist export-ignore
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ nbproject
tmp/

clover.xml
composer.lock
coveralls-upload.json
phpunit.xml
vendor
5 changes: 4 additions & 1 deletion .php_cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php
$finder = Symfony\CS\Finder\DefaultFinder::create()
->in('src')
->in('test')
->notPath('TestAsset')
->notPath('_files')
->filter(function (SplFileInfo $file) {
Expand Down Expand Up @@ -28,9 +30,10 @@ $config->fixers(
'multiple_use',
'method_argument_space',
'object_operator',
'ordered_use',
'php_closing_tag',
'psr0',
'remove_lines_between_uses',
'long_array_syntax',
'short_tag',
'standardize_not_equal',
'trailing_spaces',
Expand Down
26 changes: 20 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ sudo: false

language: php

branches:
except:
- /^release-.*$/
- /^ghgfk-.*$/

cache:
directories:
- $HOME/.composer/cache

matrix:
fast_finish: true
include:
- php: 5.3
- php: 5.4
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- EXECUTE_CS_CHECK=true
- php: 7
- php: hhvm
- php: hhvm
allow_failures:
- php: 7
- php: hhvm
Expand All @@ -22,14 +34,16 @@ notifications:

before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi

install:
- composer install --no-interaction --prefer-source
- travis_retry composer install --no-interaction --ignore-platform-reqs

script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis --coverage-clover clover.xml ; fi
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit -c phpunit.xml.travis ; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run --config-file=.php_cs ; fi
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then ./vendor/bin/phpunit ; fi
- if [[ $EXECUTE_CS_CHECK == 'true' ]]; then ./vendor/bin/php-cs-fixer fix -v --diff --dry-run ; fi

after_script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/coveralls ; fi
61 changes: 61 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,67 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.4.8 - TBD

### Added

- Nothing.

### Deprecated

- [#26](https://github.com/zendframework/zend-inputfilter/pull/26) Deprecate magic logic for auto attach a NonEmpty
validator with breakChainOnFailure = true. Instead append NonEmpty validator when desired.

```php
$input = new Zend\InputFilter\Input();
$input->setContinueIfEmpty(true);
$input->setAllowEmpty(true);
$input->getValidatorChain()->attach(new Zend\Validator\NotEmpty(), /* break chain on failure */ true);
```
### Removed

- Nothing.

### Fixed

- [#22](https://github.com/zendframework/zend-inputfilter/pull/22) adds tests to
verify two conditions around inputs with fallback values:
- If the input was not in the data set, it should not be represented in either
the list of valid *or* invalid inputs.
- If the input *was* in the data set, but empty, it should be represented in
the list of valid inputs.
- [#31](https://github.com/zendframework/zend-inputfilter/pull/31) updates the
`InputFilterInterface::add()` docblock to match existing, shipped implementations.
- [#25](https://github.com/zendframework/zend-inputfilter/pull/25) Fix missing optional fields to be required.
BC Break since 2.3.9.
For completely fix this you need to setup your inputs as follow.

```php
$input = new Input();
$input->setAllowEmpty(true); // Disable BC Break logic related to treat `null` values as valid empty value instead *not set*.
$input->setContinueIfEmpty(true); // Disable BC Break logic related to treat `null` values as valid empty value instead *not set*.
$input->getValidatorChain()->attach(
new Zend\Validator\NotEmpty(),
true // break chain on failure
);
```

```php
$inputSpecification = array(
'allow_empty' => true,
'continue_if_empty' => true,
'validators' => array(
array(
'break_chain_on_failure' => true,
'name' => 'Zend\\Validator\\NotEmpty',
),
),
);
```
- [Numerous fixes](https://github.com/zendframework/zend-inputfilter/milestones/2.4.8)
aimed at bringing the functionality back to the pre-2.4 code, and improving
quality overall of the component via increased testing and test coverage.

## 2.4.7 - 2015-08-11

### Added
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# zend-inputfilter

[![Build Status](https://secure.travis-ci.org/zendframework/zend-inputfilter.svg?branch=master)](https://secure.travis-ci.org/zendframework/zend-inputfilter)
[![Coverage Status](https://coveralls.io/repos/zendframework/zend-inputfilter/badge.svg?branch=master)](https://coveralls.io/r/zendframework/zend-inputfilter?branch=master)

The `Zend\InputFilter` component can be used to filter and validate generic sets
of input data. For instance, you could use it to filter `$_GET` or `$_POST`
values, CLI arguments, etc.
Expand Down
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@
"zf2",
"inputfilter"
],
"homepage": "https://github.com/zendframework/zend-input-filter",
"homepage": "https://github.com/zendframework/zend-inputfilter",
"autoload": {
"psr-4": {
"Zend\\InputFilter\\": "src/"
}
},
"require": {
"php": ">=5.3.23",
"zendframework/zend-filter": "self.version",
"zendframework/zend-validator": "self.version",
"zendframework/zend-stdlib": "self.version"
"zendframework/zend-filter": "~2.4.0",
"zendframework/zend-validator": "~2.4.8",
"zendframework/zend-stdlib": "~2.4.0"
},
"require-dev": {
"zendframework/zend-servicemanager": "self.version",
"zendframework/zend-servicemanager": "~2.4.0",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
"phpunit/PHPUnit": "^4.5"
},
"suggest": {
"zendframework/zend-servicemanager": "To support plugin manager support"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "2.4-dev",
Expand All @@ -38,4 +39,4 @@
"ZendTest\\InputFilter\\": "test/"
}
}
}
}
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
functionality works as expected. Such tests include those for
Zend\Soap and Zend\Session, which require that headers not be sent
in order to work. -->
<const name="TESTS_ZEND_OB_ENABLED" value="false" />
<env name="TESTS_ZEND_OB_ENABLED" value="false" />

</php>
</phpunit>
34 changes: 0 additions & 34 deletions phpunit.xml.travis

This file was deleted.

34 changes: 32 additions & 2 deletions src/ArrayInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public function setValue($value)
return parent::setValue($value);
}

/**
* {@inheritdoc}
*/
public function resetValue()
{
$this->value = array();
$this->hasValue = false;
return $this;
}

/**
* @return array
*/
Expand All @@ -50,6 +60,22 @@ public function getValue()
*/
public function isValid($context = null)
{
$hasValue = $this->hasValue();
$required = $this->isRequired();
$hasFallback = $this->hasFallback();

if (! $hasValue && $hasFallback) {
$this->setValue($this->getFallbackValue());
return true;
}

if (! $hasValue && $required) {
if ($this->errorMessage === null) {
$this->errorMessage = $this->prepareRequiredValidationFailureMessage();
}
return false;
}

if (!$this->continueIfEmpty() && !$this->allowEmpty()) {
$this->injectNotEmptyValidator();
}
Expand All @@ -58,15 +84,19 @@ public function isValid($context = null)
$result = true;
foreach ($values as $value) {
$empty = ($value === null || $value === '' || $value === array());
if ($empty && !$this->isRequired() && !$this->continueIfEmpty()) {
$result = true;
continue;
}
if ($empty && $this->allowEmpty() && !$this->continueIfEmpty()) {
$result = true;
continue;
}
$result = $validator->isValid($value, $context);
if (!$result) {
if ($this->hasFallback()) {
if ($hasFallback) {
$this->setValue($this->getFallbackValue());
$result = true;
return true;
}
break;
}
Expand Down
Loading

0 comments on commit aa16fb2

Please sign in to comment.