From 7672b5d1f02a9fbb273728e3bc774d434a76cfa3 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Tue, 3 Nov 2015 19:20:21 +0100 Subject: [PATCH 1/7] OptionsResolver test coverage --- .../Tests/LegacyOptionsResolverTest.php | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php b/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php index ee89f5279797a..a4c9346bd8604 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php +++ b/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php @@ -19,6 +19,11 @@ */ class LegacyOptionsResolverTest extends \PHPUnit_Framework_TestCase { + /** + * @var ReflectionMethod + */ + private $reflectionMethod; + /** * @var OptionsResolver */ @@ -27,6 +32,10 @@ class LegacyOptionsResolverTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->resolver = new OptionsResolver(); + + $reflectionClass = new \ReflectionClass($this->resolver); + $this->reflectionMethod = $reflectionClass->getMethod('formatValue'); + $this->reflectionMethod->setAccessible(true); } public function testResolve() @@ -730,4 +739,20 @@ public function testOverloadCallsSet() $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve()); } + + public function testFormatValueObject() + { + $this->assertEquals("Symfony\Component\OptionsResolver\OptionsResolver", $this->reflectionMethod->invoke($this->resolver, $this->resolver)); + } + + public function testFormatValueArray() + { + $this->assertEquals("array", $this->reflectionMethod->invoke($this->resolver, [])); + } + + public function testFormatValueResource() + { + $handle = fopen(__FILE__, "r"); + $this->assertEquals("resource", $this->reflectionMethod->invoke($this->resolver, $handle)); + } } From 715670398611ce41083745b865a219e56e008af2 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Wed, 4 Nov 2015 00:12:10 +0100 Subject: [PATCH 2/7] changes requested by Tobion --- .../Tests/LegacyOptionsResolverTest.php | 25 ------------- .../Tests/OptionsResolver2Dot6Test.php | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php b/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php index a4c9346bd8604..ee89f5279797a 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php +++ b/src/Symfony/Component/OptionsResolver/Tests/LegacyOptionsResolverTest.php @@ -19,11 +19,6 @@ */ class LegacyOptionsResolverTest extends \PHPUnit_Framework_TestCase { - /** - * @var ReflectionMethod - */ - private $reflectionMethod; - /** * @var OptionsResolver */ @@ -32,10 +27,6 @@ class LegacyOptionsResolverTest extends \PHPUnit_Framework_TestCase protected function setUp() { $this->resolver = new OptionsResolver(); - - $reflectionClass = new \ReflectionClass($this->resolver); - $this->reflectionMethod = $reflectionClass->getMethod('formatValue'); - $this->reflectionMethod->setAccessible(true); } public function testResolve() @@ -739,20 +730,4 @@ public function testOverloadCallsSet() $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve()); } - - public function testFormatValueObject() - { - $this->assertEquals("Symfony\Component\OptionsResolver\OptionsResolver", $this->reflectionMethod->invoke($this->resolver, $this->resolver)); - } - - public function testFormatValueArray() - { - $this->assertEquals("array", $this->reflectionMethod->invoke($this->resolver, [])); - } - - public function testFormatValueResource() - { - $handle = fopen(__FILE__, "r"); - $this->assertEquals("resource", $this->reflectionMethod->invoke($this->resolver, $handle)); - } } diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index 367ee3fecdf70..7b04feb63aadb 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -1557,4 +1557,41 @@ public function testCountFailsOutsideResolve() count($this->resolver); } + + /** + * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + * @expectedExceptionMessage The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver". + */ + public function testFormatValueObject() + { + $this->resolver->setDefined('option'); + $this->resolver->setAllowedTypes('option', 'string'); + + $this->resolver->resolve(array('option' => $this->resolver)); + } + + /** + * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + * @expectedExceptionMessage The option "option" with value array is expected to be of type "string", but is of type "array". + */ + public function testFormatValueArray() + { + $this->resolver->setDefined('option'); + $this->resolver->setAllowedTypes('option', 'string'); + + $this->resolver->resolve(array('option' => [])); + } + + /** + * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + * @expectedExceptionMessage The option "option" with value resource is expected to be of type "string", but is of type "resource". + */ + public function testFormatValueResource() + { + $this->resolver->setDefined('option'); + $this->resolver->setAllowedTypes('option', 'string'); + $handle = fopen(__FILE__, "r"); + + $this->resolver->resolve(array('option' => $handle)); + } } From 8a3d81f9dce6bba6f1496abb45d7aab8270b545d Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Wed, 4 Nov 2015 23:28:12 +0100 Subject: [PATCH 3/7] changes requested by Tobion and stof --- .../Tests/OptionsResolver2Dot6Test.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index 7b04feb63aadb..b4dc634206e29 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -1579,7 +1579,7 @@ public function testFormatValueArray() $this->resolver->setDefined('option'); $this->resolver->setAllowedTypes('option', 'string'); - $this->resolver->resolve(array('option' => [])); + $this->resolver->resolve(array('option' => array())); } /** @@ -1594,4 +1594,16 @@ public function testFormatValueResource() $this->resolver->resolve(array('option' => $handle)); } + + /** + * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + * @expectedExceptionMessage The option "option" with value true is expected to be of type "string", but is of type "boolean". + */ + public function testFormatValueTrue() + { + $this->resolver->setDefined('option'); + $this->resolver->setAllowedTypes('option', 'string'); + + $this->resolver->resolve(array('option' => true)); + } } From d629114494744503d924d8bf7eddc718fb4b1e45 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Sun, 8 Nov 2015 00:25:01 +0100 Subject: [PATCH 4/7] changes requested by Tobion --- .../Tests/OptionsResolver2Dot6Test.php | 123 +++++++----------- 1 file changed, 46 insertions(+), 77 deletions(-) diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index b4dc634206e29..1e654a11d0eb7 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -498,30 +498,6 @@ public function testFailIfSetAllowedTypesFromLazyOption() $this->resolver->resolve(); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - * @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string", but is of type "integer". - */ - public function testResolveFailsIfInvalidType() - { - $this->resolver->setDefined('foo'); - $this->resolver->setAllowedTypes('foo', 'string'); - - $this->resolver->resolve(array('foo' => 42)); - } - - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - * @expectedExceptionMessage The option "foo" with value null is expected to be of type "string", but is of type "NULL". - */ - public function testResolveFailsIfInvalidTypeIsNull() - { - $this->resolver->setDefault('foo', null); - $this->resolver->setAllowedTypes('foo', 'string'); - - $this->resolver->resolve(); - } - public function testResolveSucceedsIfValidType() { $this->resolver->setDefault('foo', 'bar'); @@ -550,17 +526,6 @@ public function testResolveSucceedsIfValidTypeMultiple() $this->assertNotEmpty($this->resolver->resolve()); } - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ - public function testResolveFailsIfNotInstanceOfClass() - { - $this->resolver->setDefault('foo', 'bar'); - $this->resolver->setAllowedTypes('foo', '\stdClass'); - - $this->resolver->resolve(); - } - public function testResolveSucceedsIfInstanceOfClass() { $this->resolver->setDefault('foo', new \stdClass()); @@ -1559,51 +1524,55 @@ public function testCountFailsOutsideResolve() } /** + * @dataProvider getFormatValueData * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - * @expectedExceptionMessage The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver". - */ - public function testFormatValueObject() - { - $this->resolver->setDefined('option'); - $this->resolver->setAllowedTypes('option', 'string'); - - $this->resolver->resolve(array('option' => $this->resolver)); - } - - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - * @expectedExceptionMessage The option "option" with value array is expected to be of type "string", but is of type "array". */ - public function testFormatValueArray() + public function testFormatValue($actualType, $allowedType, $exceptionMessage) { $this->resolver->setDefined('option'); - $this->resolver->setAllowedTypes('option', 'string'); - - $this->resolver->resolve(array('option' => array())); - } - - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - * @expectedExceptionMessage The option "option" with value resource is expected to be of type "string", but is of type "resource". - */ - public function testFormatValueResource() - { - $this->resolver->setDefined('option'); - $this->resolver->setAllowedTypes('option', 'string'); - $handle = fopen(__FILE__, "r"); - - $this->resolver->resolve(array('option' => $handle)); - } - - /** - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - * @expectedExceptionMessage The option "option" with value true is expected to be of type "string", but is of type "boolean". - */ - public function testFormatValueTrue() - { - $this->resolver->setDefined('option'); - $this->resolver->setAllowedTypes('option', 'string'); - - $this->resolver->resolve(array('option' => true)); + $this->resolver->setAllowedTypes('option', $allowedType); + + $this->resolver->resolve(array('option' => $actualType)); + } + + public function getFormatValueData() + { + return array( + array( + 'actualType' => true, + 'allowedType' => 'string', + 'exceptionMessage' => 'The option "option" with value true is expected to be of type "string", but is of type "boolean".' + ), + array( + 'actualType' => fopen(__FILE__, "r"), + 'allowedType' => 'string', + 'exceptionMessage' => 'The option "option" with value resource is expected to be of type "string", but is of type "resource".' + ), + array( + 'actualType' => array(), + 'allowedType' => 'string', + 'exceptionMessage' => 'The option "option" with value array is expected to be of type "string", but is of type "array".' + ), + array( + 'actualType' => $this->resolver, + 'allowedType' => 'string', + 'exceptionMessage' => 'The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver".' + ), + array( + 'actualType' => 42, + 'allowedType' => 'string', + 'exceptionMessage' => 'The option "option" with value 42 is expected to be of type "string", but is of type "integer".' + ), + array( + 'actualType' => null, + 'allowedType' => 'string', + 'exceptionMessage' => 'The option "option" with value null is expected to be of type "string", but is of type "NULL".' + ), + array( + 'actualType' => 'bar', + 'allowedType' => '\stdClass', + 'exceptionMessage' => '' + ), + ); } } From 2a9b860993aee5a8b277bb5e1f642ed2fded97a0 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Sun, 8 Nov 2015 00:31:55 +0100 Subject: [PATCH 5/7] fix class coverage --- .../OptionsResolver/Tests/OptionsResolver2Dot6Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index 1e654a11d0eb7..034fcaa0695d8 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -1554,7 +1554,7 @@ public function getFormatValueData() 'exceptionMessage' => 'The option "option" with value array is expected to be of type "string", but is of type "array".' ), array( - 'actualType' => $this->resolver, + 'actualType' => new OptionsResolver(), 'allowedType' => 'string', 'exceptionMessage' => 'The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver".' ), From 98581ff6d613b51bfef1c719933f63ed74d04cab Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Sun, 8 Nov 2015 16:13:34 +0100 Subject: [PATCH 6/7] changes requested by Tobion p3 --- .../Tests/OptionsResolver2Dot6Test.php | 79 ++++++------------- 1 file changed, 26 insertions(+), 53 deletions(-) diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index 034fcaa0695d8..fbd5f770a30b8 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -498,6 +498,32 @@ public function testFailIfSetAllowedTypesFromLazyOption() $this->resolver->resolve(); } + /** + * @dataProvider provideInvalidTypes + * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException + */ + public function testResolveFailsIfInvalidType($actualType, $allowedType, $exceptionMessage) + { + $this->setExpectedException('InvalidArgumentException', $exceptionMessage); + $this->resolver->setDefined('option'); + $this->resolver->setAllowedTypes('option', $allowedType); + + $this->resolver->resolve(array('option' => $actualType)); + } + + public function provideInvalidTypes() + { + return array( + array(true, 'string', 'The option "option" with value true is expected to be of type "string", but is of type "boolean".'), + array(fopen(__FILE__, "r"), 'string', 'The option "option" with value resource is expected to be of type "string", but is of type "resource".'), + array(array(), 'string', 'The option "option" with value array is expected to be of type "string", but is of type "array".'), + array(new OptionsResolver(), 'string', 'The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver".'), + array(42, 'string', 'The option "option" with value 42 is expected to be of type "string", but is of type "integer".'), + array(null, 'string', 'The option "option" with value null is expected to be of type "string", but is of type "NULL".'), + array('bar', '\stdClass', 'The option "option" with value "bar" is expected to be of type "\stdClass", but is of type "string".'), + ); + } + public function testResolveSucceedsIfValidType() { $this->resolver->setDefault('foo', 'bar'); @@ -1522,57 +1548,4 @@ public function testCountFailsOutsideResolve() count($this->resolver); } - - /** - * @dataProvider getFormatValueData - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException - */ - public function testFormatValue($actualType, $allowedType, $exceptionMessage) - { - $this->resolver->setDefined('option'); - $this->resolver->setAllowedTypes('option', $allowedType); - - $this->resolver->resolve(array('option' => $actualType)); - } - - public function getFormatValueData() - { - return array( - array( - 'actualType' => true, - 'allowedType' => 'string', - 'exceptionMessage' => 'The option "option" with value true is expected to be of type "string", but is of type "boolean".' - ), - array( - 'actualType' => fopen(__FILE__, "r"), - 'allowedType' => 'string', - 'exceptionMessage' => 'The option "option" with value resource is expected to be of type "string", but is of type "resource".' - ), - array( - 'actualType' => array(), - 'allowedType' => 'string', - 'exceptionMessage' => 'The option "option" with value array is expected to be of type "string", but is of type "array".' - ), - array( - 'actualType' => new OptionsResolver(), - 'allowedType' => 'string', - 'exceptionMessage' => 'The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver".' - ), - array( - 'actualType' => 42, - 'allowedType' => 'string', - 'exceptionMessage' => 'The option "option" with value 42 is expected to be of type "string", but is of type "integer".' - ), - array( - 'actualType' => null, - 'allowedType' => 'string', - 'exceptionMessage' => 'The option "option" with value null is expected to be of type "string", but is of type "NULL".' - ), - array( - 'actualType' => 'bar', - 'allowedType' => '\stdClass', - 'exceptionMessage' => '' - ), - ); - } } From 4f003f36de630b86d6a2a844aad9a30ccbf383e5 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 9 Nov 2015 23:28:39 +0100 Subject: [PATCH 7/7] changes requested by Tobion p4 --- .../OptionsResolver/Tests/OptionsResolver2Dot6Test.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php index fbd5f770a30b8..9158c5ba069ce 100644 --- a/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php +++ b/src/Symfony/Component/OptionsResolver/Tests/OptionsResolver2Dot6Test.php @@ -500,14 +500,12 @@ public function testFailIfSetAllowedTypesFromLazyOption() /** * @dataProvider provideInvalidTypes - * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException */ public function testResolveFailsIfInvalidType($actualType, $allowedType, $exceptionMessage) { - $this->setExpectedException('InvalidArgumentException', $exceptionMessage); $this->resolver->setDefined('option'); $this->resolver->setAllowedTypes('option', $allowedType); - + $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage); $this->resolver->resolve(array('option' => $actualType)); } @@ -515,7 +513,8 @@ public function provideInvalidTypes() { return array( array(true, 'string', 'The option "option" with value true is expected to be of type "string", but is of type "boolean".'), - array(fopen(__FILE__, "r"), 'string', 'The option "option" with value resource is expected to be of type "string", but is of type "resource".'), + array(false, 'string', 'The option "option" with value false is expected to be of type "string", but is of type "boolean".'), + array(fopen(__FILE__, 'r'), 'string', 'The option "option" with value resource is expected to be of type "string", but is of type "resource".'), array(array(), 'string', 'The option "option" with value array is expected to be of type "string", but is of type "array".'), array(new OptionsResolver(), 'string', 'The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver".'), array(42, 'string', 'The option "option" with value 42 is expected to be of type "string", but is of type "integer".'), pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy