Esempio n. 1
0
 /**
  * {@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;
 }
 /**
  * @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);
 }
Esempio n. 3
0
 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));
 }
 /**
  * {@inheritdoc}
  */
 public function setNormalizers(array $normalizers)
 {
     $this->validateOptionsExistence($normalizers);
     foreach ($normalizers as $option => $normalizer) {
         $this->defaultOptions->setNormalizer($option, $normalizer);
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * Sets normalizers that are applied on resolved options.
  *
  * The normalizers should be closures with the following signature:
  *
  * <code>
  * function (Options $options, $value)
  * </code>
  *
  * The second parameter passed to the closure is the value of
  * the option.
  *
  * The closure should return the normalized value.
  *
  * @param array $normalizers An array of closures
  *
  * @return OptionsConfig This configuration instance
  */
 public function setNormalizers(array $normalizers)
 {
     Options::validateNames($normalizers, $this->knownOptions, true);
     foreach ($normalizers as $option => $normalizer) {
         $this->defaultOptions->setNormalizer($option, $normalizer);
     }
     return $this;
 }
Esempio n. 6
0
 public function testNormalizerWithoutCorrespondingOption()
 {
     $test = $this;
     $this->options->setNormalizer('foo', function (Options $options, $previousValue) use($test) {
         $test->assertNull($previousValue);
         return '';
     });
     $this->assertEquals(array('foo' => ''), $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);
 }
Esempio n. 8
0
    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;
 }
Esempio n. 10
0
 public function testHasWithNullValue()
 {
     $this->options->set('foo', null);
     $this->assertTrue($this->options->has('foo'));
 }