示例#1
0
 /**
  * Sets default option values.
  *
  * @param array $defaultValues A list of option names as keys and default values
  *                             as values. The option values may be closures
  *                             of the following signatures:
  *
  *                                 - function (Options $options)
  *                                 - function (Options $options, $previousValue)
  *
  * @return OptionsResolver The resolver instance.
  */
 public function setDefaults(array $defaultValues)
 {
     foreach ($defaultValues as $option => $value) {
         $this->defaultOptions->overload($option, $value);
         $this->knownOptions[$option] = true;
     }
     return $this;
 }
示例#2
0
 public function testOverloadCannotBeEvaluatedLazilyWithoutFirstParamTypeHint()
 {
     $this->options->set('foo', 'bar');
     $this->options->overload('foo', function ($object) {
         return 'test';
     });
     $this->assertNotEquals('test', $this->options->get('foo'));
     $this->assertTrue(is_callable($this->options->get('foo')));
 }
示例#3
0
    public function testPreviousValueIsEvaluatedIfLazy()
    {
        $test = $this;

        // defined by superclass
        $this->options->set('foo', function (Options $options) {
            return 'bar';
        });

        // defined by subclass
        $this->options->overload('foo', function (Options $options, $previousValue) use ($test) {
            /* @var \PHPUnit_Framework_TestCase $test */
            $test->assertEquals('bar', $previousValue);

            return 'dynamic';
        });

        $this->assertEquals('dynamic', $this->options->get('foo'));
    }