/** * 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; }
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'))); }
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')); }