/** * {@inheritdoc} */ public function replaceDefaults(array $defaultValues) { foreach ($defaultValues as $option => $value) { $this->defaultOptions->set($option, $value); $this->knownOptions[$option] = true; unset($this->requiredOptions[$option]); } return $this; }
public function testOptionsIteration() { $this->options->set('foo', 'bar'); $this->options->set('foo1', 'bar1'); $expectedResult = array('foo' => 'bar', 'foo1' => 'bar1'); $this->assertEquals($expectedResult, iterator_to_array($this->options, true)); }
/** * @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException * @expectedExceptionMessage Expected argument of type "Attribute", "DateTime" given */ public function testSetDefaultOptionsInvalidAttribute() { $resolver = $this->getMock('Symfony\\Component\\OptionsResolver\\OptionsResolverInterface'); $resolver->expects($this->once())->method('setNormalizers')->with($this->isType('array'))->willReturnCallback(function (array $normalizers) { $options = new Options(); $options->set('attribute', new \DateTime()); /** @var \Closure $normalizerCallback */ $normalizerCallback = $normalizers['query_builder']; $normalizerCallback($options); }); $this->formType->setDefaultOptions($resolver); }
public function testClearOptionAndNormalizer() { $this->options->set('foo1', 'bar'); $this->options->setNormalizer('foo1', function (Options $options) { return ''; }); $this->options->set('foo2', 'bar'); $this->options->setNormalizer('foo2', function (Options $options) { return ''; }); $this->options->clear(); $this->assertEmpty($this->options->all()); }
public function testSetDefaultOptions() { $resolver = $this->getMock('Symfony\\Component\\OptionsResolver\\OptionsResolverInterface'); $resolver->expects($this->once())->method('setRequired')->with(array('workflow_item', 'transition_name')); $resolver->expects($this->once())->method('setAllowedTypes')->with(array('transition_name' => 'string')); $resolver->expects($this->once())->method('setNormalizers')->will($this->returnCallback(function ($value) { $this->assertInternalType('array', $value); $this->assertArrayHasKey('constraints', $value); $this->assertInternalType('callable', $value['constraints']); $workflowItem = $this->getMock('Oro\\Bundle\\WorkflowBundle\\Entity\\WorkflowItem'); $transitionName = 'test_transition'; $options = new Options(); $options->set('workflow_item', $workflowItem); $options->set('transition_name', $transitionName); $constraints = array(); $constraints = $value['constraints']($options, $constraints); $this->assertInstanceOf('Oro\\Bundle\\WorkflowBundle\\Validator\\Constraints\\TransitionIsAllowed', $constraints[0]); $this->assertEquals($workflowItem, $constraints[0]->getWorkflowItem()); $this->assertEquals($transitionName, $constraints[0]->getTransitionName()); })); $this->type->setDefaultOptions($resolver); }
public function testReplaceClearsAndSets() { $this->options->set('one', '1'); $this->options->replace(array( 'two' => '2', 'three' => function (Options $options) { return '2' === $options['two'] ? '3' : 'foo'; } )); $this->assertEquals(array( 'two' => '2', 'three' => '3', ), $this->options->all()); }
/** * @param array $options * @return Options */ protected function getResolverOptions($options) { $resolverOptions = new Options(); foreach ($options as $key => $value) { $resolverOptions->set($key, $value); } return $resolverOptions; }
public function testHasWithNullValue() { $this->options->set('foo', null); $this->assertTrue($this->options->has('foo')); }