From 888f831edcdc95840b24aef3af4aaf902bb15966 Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Thu, 7 Nov 2013 15:23:54 +0100 Subject: [PATCH 1/4] psr-2 --- src/Filter/Alnum.php | 2 +- src/Filter/Alpha.php | 2 +- src/Filter/NumberFormat.php | 2 +- test/Filter/AlnumTest.php | 12 ++++++------ test/Filter/AlphaTest.php | 14 +++++++------- test/Filter/NumberFormatTest.php | 8 ++++---- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Filter/Alnum.php b/src/Filter/Alnum.php index ebab41f4..c445bda2 100644 --- a/src/Filter/Alnum.php +++ b/src/Filter/Alnum.php @@ -76,7 +76,7 @@ public function filter($value) if(!is_scalar($value) && !is_array($value)){ return $value; } - + $whiteSpace = $this->options['allow_white_space'] ? '\s' : ''; $language = Locale::getPrimaryLanguage($this->getLocale()); diff --git a/src/Filter/Alpha.php b/src/Filter/Alpha.php index d3f57ee3..2c418680 100644 --- a/src/Filter/Alpha.php +++ b/src/Filter/Alpha.php @@ -26,7 +26,7 @@ public function filter($value) if(!is_scalar($value) && !is_array($value)){ return $value; } - + $whiteSpace = $this->options['allow_white_space'] ? '\s' : ''; $language = Locale::getPrimaryLanguage($this->getLocale()); diff --git a/src/Filter/NumberFormat.php b/src/Filter/NumberFormat.php index 1904cdb5..eb9dc481 100644 --- a/src/Filter/NumberFormat.php +++ b/src/Filter/NumberFormat.php @@ -143,7 +143,7 @@ public function filter($value) if(!is_scalar($value)){ return $value; } - + $formatter = $this->getFormatter(); $type = $this->getType(); diff --git a/test/Filter/AlnumTest.php b/test/Filter/AlnumTest.php index 0b339d03..d53d92af 100644 --- a/test/Filter/AlnumTest.php +++ b/test/Filter/AlnumTest.php @@ -158,11 +158,11 @@ public function testAllowWhiteSpace() $this->assertEquals($expected, $actual); } } - + public function testFilterSupportArray() { $filter = new AlnumFilter(); - + $values = array( 'abc123' => 'abc123', 'abc 123' => 'abc123', @@ -170,16 +170,16 @@ public function testFilterSupportArray() 'AZ@#4.3' => 'AZ43', '' => '' ); - + $actual = $filter->filter(array_keys($values)); - + $this->assertEquals(array_values($values), $actual); } - + public function testReturnUnfiltered() { $filter = new AlnumFilter(); - + $valuesExpected = array( null, new \stdClass() diff --git a/test/Filter/AlphaTest.php b/test/Filter/AlphaTest.php index 5961e8a9..a3804070 100644 --- a/test/Filter/AlphaTest.php +++ b/test/Filter/AlphaTest.php @@ -162,27 +162,27 @@ public function testAllowWhiteSpace() $this->assertEquals($expected, $actual); } } - + public function testFilterSupportArray() { $filter = new AlphaFilter(); - + $values = array( 'abc123' => 'abc', 'abc 123' => 'abc', 'abcxyz' => 'abcxyz', '' => '' ); - + $actual = $filter->filter(array_keys($values)); - + $this->assertEquals(array_values($values), $actual); } - + public function testReturnUnfiltered() { $filter = new AlphaFilter(); - + $valuesExpected = array( null, new \stdClass() @@ -191,5 +191,5 @@ public function testReturnUnfiltered() $this->assertEquals($input, $filter->filter($input)); } } - + } diff --git a/test/Filter/NumberFormatTest.php b/test/Filter/NumberFormatTest.php index 945fcff2..8244a8ca 100644 --- a/test/Filter/NumberFormatTest.php +++ b/test/Filter/NumberFormatTest.php @@ -139,15 +139,15 @@ public function formattedToNumberProvider() ), ); } - - + + public function testReturnUnfiltered() { $filter = new NumberFormatFilter('de_AT', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE); $this->assertEquals($expected, $filter->filter($value)); - + $filter = new AlphaFilter(); - + $valuesExpected = array( null, new \stdClass(), From 03c87b2fb3ffbf810fec348bd8a96ff24dc1e6bf Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Thu, 9 Jan 2014 14:07:01 +0100 Subject: [PATCH 2/4] PSR spacing fun for IF :-) --- src/Filter/Alnum.php | 2 +- src/Filter/Alpha.php | 2 +- src/Filter/NumberFormat.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Filter/Alnum.php b/src/Filter/Alnum.php index c445bda2..b943b4c8 100644 --- a/src/Filter/Alnum.php +++ b/src/Filter/Alnum.php @@ -73,7 +73,7 @@ public function getAllowWhiteSpace() */ public function filter($value) { - if(!is_scalar($value) && !is_array($value)){ + if (!is_scalar($value) && !is_array($value)) { return $value; } diff --git a/src/Filter/Alpha.php b/src/Filter/Alpha.php index 2c418680..1cf971bd 100644 --- a/src/Filter/Alpha.php +++ b/src/Filter/Alpha.php @@ -23,7 +23,7 @@ class Alpha extends Alnum */ public function filter($value) { - if(!is_scalar($value) && !is_array($value)){ + if (!is_scalar($value) && !is_array($value)) { return $value; } diff --git a/src/Filter/NumberFormat.php b/src/Filter/NumberFormat.php index eb9dc481..3b3a7a91 100644 --- a/src/Filter/NumberFormat.php +++ b/src/Filter/NumberFormat.php @@ -140,7 +140,7 @@ public function getFormatter() */ public function filter($value) { - if(!is_scalar($value)){ + if (!is_scalar($value)) { return $value; } From 593acacc4e435e01c13c119e7d1e3f60cc51451e Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Fri, 10 Jan 2014 10:10:30 +0100 Subject: [PATCH 3/4] @dataProvider for testReturnUnfiltered --- test/Filter/AlnumTest.php | 22 ++++++++++++++-------- test/Filter/AlphaTest.php | 22 ++++++++++++++-------- test/Filter/NumberFormatTest.php | 31 +++++++++++++++++-------------- 3 files changed, 45 insertions(+), 30 deletions(-) diff --git a/test/Filter/AlnumTest.php b/test/Filter/AlnumTest.php index d53d92af..3a62e495 100644 --- a/test/Filter/AlnumTest.php +++ b/test/Filter/AlnumTest.php @@ -176,16 +176,22 @@ public function testFilterSupportArray() $this->assertEquals(array_values($values), $actual); } - public function testReturnUnfiltered() + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) { $filter = new AlnumFilter(); - $valuesExpected = array( - null, - new \stdClass() - ); - foreach ($valuesExpected as $input) { - $this->assertEquals($input, $filter->filter($input)); - } + $this->assertEquals($input, $filter->filter($input)); } } diff --git a/test/Filter/AlphaTest.php b/test/Filter/AlphaTest.php index a3804070..2200869e 100644 --- a/test/Filter/AlphaTest.php +++ b/test/Filter/AlphaTest.php @@ -179,17 +179,23 @@ public function testFilterSupportArray() $this->assertEquals(array_values($values), $actual); } - public function testReturnUnfiltered() + public function returnUnfilteredDataProvider() + { + return array( + array(null), + array(new \stdClass()) + ); + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) { $filter = new AlphaFilter(); - $valuesExpected = array( - null, - new \stdClass() - ); - foreach ($valuesExpected as $input) { - $this->assertEquals($input, $filter->filter($input)); - } + $this->assertEquals($input, $filter->filter($input)); } } diff --git a/test/Filter/NumberFormatTest.php b/test/Filter/NumberFormatTest.php index 8244a8ca..f2bce171 100644 --- a/test/Filter/NumberFormatTest.php +++ b/test/Filter/NumberFormatTest.php @@ -141,23 +141,26 @@ public function formattedToNumberProvider() } - public function testReturnUnfiltered() + public function returnUnfilteredDataProvider() { - $filter = new NumberFormatFilter('de_AT', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE); - $this->assertEquals($expected, $filter->filter($value)); - - $filter = new AlphaFilter(); - - $valuesExpected = array( - null, - new \stdClass(), - array( + return array( + array(null), + array(new \stdClass()), + array(array( '1.234.567,891', '1.567,891' - ) + )) ); - foreach ($valuesExpected as $input) { - $this->assertEquals($input, $filter->filter($input)); - } + } + + /** + * @dataProvider returnUnfilteredDataProvider + * @return void + */ + public function testReturnUnfiltered($input) + { + $filter = new NumberFormatFilter('de_AT', NumberFormatter::DEFAULT_STYLE, NumberFormatter::TYPE_DOUBLE); + + $this->assertEquals($input, $filter->filter($input)); } } From bb9327f755e1232f9ff9a6752d2b2c5d7ed97b36 Mon Sep 17 00:00:00 2001 From: Martin Keckeis Date: Fri, 10 Jan 2014 10:14:32 +0100 Subject: [PATCH 4/4] PSR-2 (php-cs-fixer level=psr2) --- test/Filter/AlnumTest.php | 2 +- test/Filter/AlphaTest.php | 2 +- test/Filter/NumberFormatTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Filter/AlnumTest.php b/test/Filter/AlnumTest.php index 3a62e495..39a061cc 100644 --- a/test/Filter/AlnumTest.php +++ b/test/Filter/AlnumTest.php @@ -183,7 +183,7 @@ public function returnUnfilteredDataProvider() array(new \stdClass()) ); } - + /** * @dataProvider returnUnfilteredDataProvider * @return void diff --git a/test/Filter/AlphaTest.php b/test/Filter/AlphaTest.php index 2200869e..405c904b 100644 --- a/test/Filter/AlphaTest.php +++ b/test/Filter/AlphaTest.php @@ -186,7 +186,7 @@ public function returnUnfilteredDataProvider() array(new \stdClass()) ); } - + /** * @dataProvider returnUnfilteredDataProvider * @return void diff --git a/test/Filter/NumberFormatTest.php b/test/Filter/NumberFormatTest.php index f2bce171..057c2fcd 100644 --- a/test/Filter/NumberFormatTest.php +++ b/test/Filter/NumberFormatTest.php @@ -152,7 +152,7 @@ public function returnUnfilteredDataProvider() )) ); } - + /** * @dataProvider returnUnfilteredDataProvider * @return void