8000 [OptionsResolver] support array of instance validation by EVODelavega · Pull Request #17032 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[OptionsResolver] support array of instance validation #17032

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 22 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add 2 successful testcases
  • Loading branch information
Elias Van Ootegem authored and EVODelavega committed Dec 21, 2015
commit 0194c25a0e16715a9c9d70958d9cc346e2e45dd6
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,46 @@ public function testResolveSucceedsIfValidTypeMultiple()
$this->assertNotEmpty($this->resolver->resolve());
}

public function testResolveSucceedsIfTypedArray()
{
$this->resolver->setDefault('foo', null);
$this->resolver->setAllowedTypes('foo', array('null', '\DateTime[]'));

$data = array(
'foo' => array(
new \DateTime(),
new \DateTime(),
)
);
$result = $this->resolver->resolve($data);
$this->assertEquals($data, $result);
}

public function testResolveSucceedsNestedTypedArray()
{
$this->resolver->setDefault('foo', null);
$this->resolver->setAllowedTypes('foo', 'int[][]');

$expect = array(
'foo' => array(
range(1, 10),
),
);
$result = $this->resolver->resolve($expect);
$this->assertEquals($expect, $result);
}

/**
* @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