8000 OptionsResolver test coverage by eventhorizonpl · Pull Request #16446 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

OptionsResolver test coverage #16446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -499,27 +499,28 @@ public function testFailIfSetAllowedTypesFromLazyOption()
}

/**
* @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".
* @dataProvider provideInvalidTypes
*/
public function testResolveFailsIfInvalidType()
public function testResolveFailsIfInvalidType($actualType, $allowedType, $exceptionMessage)
{
$this->resolver->setDefined('foo');
$this->resolver->setAllowedTypes('foo', 'string');

$this->resolver->resolve(array('foo' => 42));
$this->resolver->setDefined('option');
$this->resolver->setAllowedTypes('option', $allowedType);
$this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage);
$this->resolver->resolve(array('option' => $actualType));
}

/**
* @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()
public function provideInvalidTypes()
{
$this->resolver->setDefault('foo', null);
$this->resolver->setAllowedTypes('foo', 'string');

$this->resolver->resolve();
return array(
array(true, 'string', 'The option "option" with value true is expected to be of type "string", but is of type "boolean".'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false is missing as test

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".'),
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()
Expand Down Expand Up @@ -550,17 +551,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());
Expand Down
0