How to use resolve method of resolver class

Best Atoum code snippet using resolver.resolve

OptionsResolver2Dot6Test.php

Source:OptionsResolver2Dot6Test.php Github

copy

Full Screen

...15{16 /**17 * @var OptionsResolver18 */19 private $resolver;20 protected function setUp()21 {22 $this->resolver = new OptionsResolver();23 }24 ////////////////////////////////////////////////////////////////////////////25 // resolve()26 ////////////////////////////////////////////////////////////////////////////27 /**28 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException29 * @expectedExceptionMessage The option "foo" does not exist. Known options are: "a", "z".30 */31 public function testResolveFailsIfNonExistingOption()32 {33 $this->resolver->setDefault('z', '1');34 $this->resolver->setDefault('a', '2');35 $this->resolver->resolve(array('foo' => 'bar'));36 }37 /**38 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException39 * @expectedExceptionMessage The options "baz", "foo", "ping" do not exist. Known options are: "a", "z".40 */41 public function testResolveFailsIfMultipleNonExistingOptions()42 {43 $this->resolver->setDefault('z', '1');44 $this->resolver->setDefault('a', '2');45 $this->resolver->resolve(array('ping' => 'pong', 'foo' => 'bar', 'baz' => 'bam'));46 }47 /**48 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException49 */50 public function testResolveFailsFromLazyOption()51 {52 $this->resolver->setDefault('foo', function (Options $options) {53 $options->resolve(array());54 });55 $this->resolver->resolve();56 }57 ////////////////////////////////////////////////////////////////////////////58 // setDefault()/hasDefault()59 ////////////////////////////////////////////////////////////////////////////60 public function testSetDefaultReturnsThis()61 {62 $this->assertSame($this->resolver, $this->resolver->setDefault('foo', 'bar'));63 }64 public function testSetDefault()65 {66 $this->resolver->setDefault('one', '1');67 $this->resolver->setDefault('two', '20');68 $this->assertEquals(array(69 'one' => '1',70 'two' => '20',71 ), $this->resolver->resolve());72 }73 /**74 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException75 */76 public function testFailIfSetDefaultFromLazyOption()77 {78 $this->resolver->setDefault('lazy', function (Options $options) {79 $options->setDefault('default', 42);80 });81 $this->resolver->resolve();82 }83 public function testHasDefault()84 {85 $this->assertFalse($this->resolver->hasDefault('foo'));86 $this->resolver->setDefault('foo', 42);87 $this->assertTrue($this->resolver->hasDefault('foo'));88 }89 public function testHasDefaultWithNullValue()90 {91 $this->assertFalse($this->resolver->hasDefault('foo'));92 $this->resolver->setDefault('foo', null);93 $this->assertTrue($this->resolver->hasDefault('foo'));94 }95 ////////////////////////////////////////////////////////////////////////////96 // overload()97 ////////////////////////////////////////////////////////////////////////////98 public function testOverloadReturnsThis()99 {100 $this->assertSame($this->resolver, $this->resolver->overload('foo', 'bar'));101 }102 public function testOverloadCallsSet()103 {104 $this->resolver->overload('foo', 'bar');105 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());106 }107 ////////////////////////////////////////////////////////////////////////////108 // lazy setDefault()109 ////////////////////////////////////////////////////////////////////////////110 public function testSetLazyReturnsThis()111 {112 $this->assertSame($this->resolver, $this->resolver->setDefault('foo', function (Options $options) {}));113 }114 public function testSetLazyClosure()115 {116 $this->resolver->setDefault('foo', function (Options $options) {117 return 'lazy';118 });119 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());120 }121 public function testClosureWithoutTypeHintNotInvoked()122 {123 $closure = function ($options) {124 \PHPUnit_Framework_Assert::fail('Should not be called');125 };126 $this->resolver->setDefault('foo', $closure);127 $this->assertSame(array('foo' => $closure), $this->resolver->resolve());128 }129 public function testClosureWithoutParametersNotInvoked()130 {131 $closure = function () {132 \PHPUnit_Framework_Assert::fail('Should not be called');133 };134 $this->resolver->setDefault('foo', $closure);135 $this->assertSame(array('foo' => $closure), $this->resolver->resolve());136 }137 public function testAccessPreviousDefaultValue()138 {139 // defined by superclass140 $this->resolver->setDefault('foo', 'bar');141 // defined by subclass142 $this->resolver->setDefault('foo', function (Options $options, $previousValue) {143 \PHPUnit_Framework_Assert::assertEquals('bar', $previousValue);144 return 'lazy';145 });146 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());147 }148 public function testAccessPreviousLazyDefaultValue()149 {150 // defined by superclass151 $this->resolver->setDefault('foo', function (Options $options) {152 return 'bar';153 });154 // defined by subclass155 $this->resolver->setDefault('foo', function (Options $options, $previousValue) {156 \PHPUnit_Framework_Assert::assertEquals('bar', $previousValue);157 return 'lazy';158 });159 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());160 }161 public function testPreviousValueIsNotEvaluatedIfNoSecondArgument()162 {163 // defined by superclass164 $this->resolver->setDefault('foo', function () {165 \PHPUnit_Framework_Assert::fail('Should not be called');166 });167 // defined by subclass, no $previousValue argument defined!168 $this->resolver->setDefault('foo', function (Options $options) {169 return 'lazy';170 });171 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());172 }173 public function testOverwrittenLazyOptionNotEvaluated()174 {175 $this->resolver->setDefault('foo', function (Options $options) {176 \PHPUnit_Framework_Assert::fail('Should not be called');177 });178 $this->resolver->setDefault('foo', 'bar');179 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());180 }181 public function testInvokeEachLazyOptionOnlyOnce()182 {183 $calls = 0;184 $this->resolver->setDefault('lazy1', function (Options $options) use (&$calls) {185 \PHPUnit_Framework_Assert::assertSame(1, ++$calls);186 $options['lazy2'];187 });188 $this->resolver->setDefault('lazy2', function (Options $options) use (&$calls) {189 \PHPUnit_Framework_Assert::assertSame(2, ++$calls);190 });191 $this->resolver->resolve();192 $this->assertSame(2, $calls);193 }194 ////////////////////////////////////////////////////////////////////////////195 // setRequired()/isRequired()/getRequiredOptions()196 ////////////////////////////////////////////////////////////////////////////197 public function testSetRequiredReturnsThis()198 {199 $this->assertSame($this->resolver, $this->resolver->setRequired('foo'));200 }201 /**202 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException203 */204 public function testFailIfSetRequiredFromLazyOption()205 {206 $this->resolver->setDefault('foo', function (Options $options) {207 $options->setRequired('bar');208 });209 $this->resolver->resolve();210 }211 /**212 * @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException213 */214 public function testResolveFailsIfRequiredOptionMissing()215 {216 $this->resolver->setRequired('foo');217 $this->resolver->resolve();218 }219 public function testResolveSucceedsIfRequiredOptionSet()220 {221 $this->resolver->setRequired('foo');222 $this->resolver->setDefault('foo', 'bar');223 $this->assertNotEmpty($this->resolver->resolve());224 }225 public function testResolveSucceedsIfRequiredOptionPassed()226 {227 $this->resolver->setRequired('foo');228 $this->assertNotEmpty($this->resolver->resolve(array('foo' => 'bar')));229 }230 public function testIsRequired()231 {232 $this->assertFalse($this->resolver->isRequired('foo'));233 $this->resolver->setRequired('foo');234 $this->assertTrue($this->resolver->isRequired('foo'));235 }236 public function testRequiredIfSetBefore()237 {238 $this->assertFalse($this->resolver->isRequired('foo'));239 $this->resolver->setDefault('foo', 'bar');240 $this->resolver->setRequired('foo');241 $this->assertTrue($this->resolver->isRequired('foo'));242 }243 public function testStillRequiredAfterSet()244 {245 $this->assertFalse($this->resolver->isRequired('foo'));246 $this->resolver->setRequired('foo');247 $this->resolver->setDefault('foo', 'bar');248 $this->assertTrue($this->resolver->isRequired('foo'));249 }250 public function testIsNotRequiredAfterRemove()251 {252 $this->assertFalse($this->resolver->isRequired('foo'));253 $this->resolver->setRequired('foo');254 $this->resolver->remove('foo');255 $this->assertFalse($this->resolver->isRequired('foo'));256 }257 public function testIsNotRequiredAfterClear()258 {259 $this->assertFalse($this->resolver->isRequired('foo'));260 $this->resolver->setRequired('foo');261 $this->resolver->clear();262 $this->assertFalse($this->resolver->isRequired('foo'));263 }264 public function testGetRequiredOptions()265 {266 $this->resolver->setRequired(array('foo', 'bar'));267 $this->resolver->setDefault('bam', 'baz');268 $this->resolver->setDefault('foo', 'boo');269 $this->assertSame(array('foo', 'bar'), $this->resolver->getRequiredOptions());270 }271 ////////////////////////////////////////////////////////////////////////////272 // isMissing()/getMissingOptions()273 ////////////////////////////////////////////////////////////////////////////274 public function testIsMissingIfNotSet()275 {276 $this->assertFalse($this->resolver->isMissing('foo'));277 $this->resolver->setRequired('foo');278 $this->assertTrue($this->resolver->isMissing('foo'));279 }280 public function testIsNotMissingIfSet()281 {282 $this->resolver->setDefault('foo', 'bar');283 $this->assertFalse($this->resolver->isMissing('foo'));284 $this->resolver->setRequired('foo');285 $this->assertFalse($this->resolver->isMissing('foo'));286 }287 public function testIsNotMissingAfterRemove()288 {289 $this->resolver->setRequired('foo');290 $this->resolver->remove('foo');291 $this->assertFalse($this->resolver->isMissing('foo'));292 }293 public function testIsNotMissingAfterClear()294 {295 $this->resolver->setRequired('foo');296 $this->resolver->clear();297 $this->assertFalse($this->resolver->isRequired('foo'));298 }299 public function testGetMissingOptions()300 {301 $this->resolver->setRequired(array('foo', 'bar'));302 $this->resolver->setDefault('bam', 'baz');303 $this->resolver->setDefault('foo', 'boo');304 $this->assertSame(array('bar'), $this->resolver->getMissingOptions());305 }306 ////////////////////////////////////////////////////////////////////////////307 // setDefined()/isDefined()/getDefinedOptions()308 ////////////////////////////////////////////////////////////////////////////309 /**310 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException311 */312 public function testFailIfSetDefinedFromLazyOption()313 {314 $this->resolver->setDefault('foo', function (Options $options) {315 $options->setDefined('bar');316 });317 $this->resolver->resolve();318 }319 public function testDefinedOptionsNotIncludedInResolvedOptions()320 {321 $this->resolver->setDefined('foo');322 $this->assertSame(array(), $this->resolver->resolve());323 }324 public function testDefinedOptionsIncludedIfDefaultSetBefore()325 {326 $this->resolver->setDefault('foo', 'bar');327 $this->resolver->setDefined('foo');328 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());329 }330 public function testDefinedOptionsIncludedIfDefaultSetAfter()331 {332 $this->resolver->setDefined('foo');333 $this->resolver->setDefault('foo', 'bar');334 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());335 }336 public function testDefinedOptionsIncludedIfPassedToResolve()337 {338 $this->resolver->setDefined('foo');339 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve(array('foo' => 'bar')));340 }341 public function testIsDefined()342 {343 $this->assertFalse($this->resolver->isDefined('foo'));344 $this->resolver->setDefined('foo');345 $this->assertTrue($this->resolver->isDefined('foo'));346 }347 public function testLazyOptionsAreDefined()348 {349 $this->assertFalse($this->resolver->isDefined('foo'));350 $this->resolver->setDefault('foo', function (Options $options) {});351 $this->assertTrue($this->resolver->isDefined('foo'));352 }353 public function testRequiredOptionsAreDefined()354 {355 $this->assertFalse($this->resolver->isDefined('foo'));356 $this->resolver->setRequired('foo');357 $this->assertTrue($this->resolver->isDefined('foo'));358 }359 public function testSetOptionsAreDefined()360 {361 $this->assertFalse($this->resolver->isDefined('foo'));362 $this->resolver->setDefault('foo', 'bar');363 $this->assertTrue($this->resolver->isDefined('foo'));364 }365 public function testGetDefinedOptions()366 {367 $this->resolver->setDefined(array('foo', 'bar'));368 $this->resolver->setDefault('baz', 'bam');369 $this->resolver->setRequired('boo');370 $this->assertSame(array('foo', 'bar', 'baz', 'boo'), $this->resolver->getDefinedOptions());371 }372 public function testRemovedOptionsAreNotDefined()373 {374 $this->assertFalse($this->resolver->isDefined('foo'));375 $this->resolver->setDefined('foo');376 $this->assertTrue($this->resolver->isDefined('foo'));377 $this->resolver->remove('foo');378 $this->assertFalse($this->resolver->isDefined('foo'));379 }380 public function testClearedOptionsAreNotDefined()381 {382 $this->assertFalse($this->resolver->isDefined('foo'));383 $this->resolver->setDefined('foo');384 $this->assertTrue($this->resolver->isDefined('foo'));385 $this->resolver->clear();386 $this->assertFalse($this->resolver->isDefined('foo'));387 }388 ////////////////////////////////////////////////////////////////////////////389 // setAllowedTypes()390 ////////////////////////////////////////////////////////////////////////////391 /**392 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException393 */394 public function testSetAllowedTypesFailsIfUnknownOption()395 {396 $this->resolver->setAllowedTypes('foo', 'string');397 }398 /**399 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException400 */401 public function testFailIfSetAllowedTypesFromLazyOption()402 {403 $this->resolver->setDefault('foo', function (Options $options) {404 $options->setAllowedTypes('bar', 'string');405 });406 $this->resolver->setDefault('bar', 'baz');407 $this->resolver->resolve();408 }409 /**410 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException411 * @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string", but is of type "integer".412 */413 public function testResolveFailsIfInvalidType()414 {415 $this->resolver->setDefault('foo', 42);416 $this->resolver->setAllowedTypes('foo', 'string');417 $this->resolver->resolve();418 }419 public function testResolveSucceedsIfValidType()420 {421 $this->resolver->setDefault('foo', 'bar');422 $this->resolver->setAllowedTypes('foo', 'string');423 $this->assertNotEmpty($this->resolver->resolve());424 }425 /**426 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException427 * @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string" or "bool", but is of type "integer".428 */429 public function testResolveFailsIfInvalidTypeMultiple()430 {431 $this->resolver->setDefault('foo', 42);432 $this->resolver->setAllowedTypes('foo', array('string', 'bool'));433 $this->resolver->resolve();434 }435 public function testResolveSucceedsIfValidTypeMultiple()436 {437 $this->resolver->setDefault('foo', true);438 $this->resolver->setAllowedTypes('foo', array('string', 'bool'));439 $this->assertNotEmpty($this->resolver->resolve());440 }441 /**442 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException443 */444 public function testResolveFailsIfNotInstanceOfClass()445 {446 $this->resolver->setDefault('foo', 'bar');447 $this->resolver->setAllowedTypes('foo', '\stdClass');448 $this->resolver->resolve();449 }450 public function testResolveSucceedsIfInstanceOfClass()451 {452 $this->resolver->setDefault('foo', new \stdClass());453 $this->resolver->setAllowedTypes('foo', '\stdClass');454 $this->assertNotEmpty($this->resolver->resolve());455 }456 ////////////////////////////////////////////////////////////////////////////457 // addAllowedTypes()458 ////////////////////////////////////////////////////////////////////////////459 /**460 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException461 */462 public function testAddAllowedTypesFailsIfUnknownOption()463 {464 $this->resolver->addAllowedTypes('foo', 'string');465 }466 /**467 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException468 */469 public function testFailIfAddAllowedTypesFromLazyOption()470 {471 $this->resolver->setDefault('foo', function (Options $options) {472 $options->addAllowedTypes('bar', 'string');473 });474 $this->resolver->setDefault('bar', 'baz');475 $this->resolver->resolve();476 }477 /**478 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException479 */480 public function testResolveFailsIfInvalidAddedType()481 {482 $this->resolver->setDefault('foo', 42);483 $this->resolver->addAllowedTypes('foo', 'string');484 $this->resolver->resolve();485 }486 public function testResolveSucceedsIfValidAddedType()487 {488 $this->resolver->setDefault('foo', 'bar');489 $this->resolver->addAllowedTypes('foo', 'string');490 $this->assertNotEmpty($this->resolver->resolve());491 }492 /**493 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException494 */495 public function testResolveFailsIfInvalidAddedTypeMultiple()496 {497 $this->resolver->setDefault('foo', 42);498 $this->resolver->addAllowedTypes('foo', array('string', 'bool'));499 $this->resolver->resolve();500 }501 public function testResolveSucceedsIfValidAddedTypeMultiple()502 {503 $this->resolver->setDefault('foo', 'bar');504 $this->resolver->addAllowedTypes('foo', array('string', 'bool'));505 $this->assertNotEmpty($this->resolver->resolve());506 }507 public function testAddAllowedTypesDoesNotOverwrite()508 {509 $this->resolver->setDefault('foo', 'bar');510 $this->resolver->setAllowedTypes('foo', 'string');511 $this->resolver->addAllowedTypes('foo', 'bool');512 $this->resolver->setDefault('foo', 'bar');513 $this->assertNotEmpty($this->resolver->resolve());514 }515 public function testAddAllowedTypesDoesNotOverwrite2()516 {517 $this->resolver->setDefault('foo', 'bar');518 $this->resolver->setAllowedTypes('foo', 'string');519 $this->resolver->addAllowedTypes('foo', 'bool');520 $this->resolver->setDefault('foo', false);521 $this->assertNotEmpty($this->resolver->resolve());522 }523 ////////////////////////////////////////////////////////////////////////////524 // setAllowedValues()525 ////////////////////////////////////////////////////////////////////////////526 /**527 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException528 */529 public function testSetAllowedValuesFailsIfUnknownOption()530 {531 $this->resolver->setAllowedValues('foo', 'bar');532 }533 /**534 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException535 */536 public function testFailIfSetAllowedValuesFromLazyOption()537 {538 $this->resolver->setDefault('foo', function (Options $options) {539 $options->setAllowedValues('bar', 'baz');540 });541 $this->resolver->setDefault('bar', 'baz');542 $this->resolver->resolve();543 }544 /**545 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException546 * @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar".547 */548 public function testResolveFailsIfInvalidValue()549 {550 $this->resolver->setDefault('foo', 42);551 $this->resolver->setAllowedValues('foo', 'bar');552 $this->resolver->resolve();553 }554 /**555 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException556 */557 public function testResolveFailsIfInvalidValueStrict()558 {559 $this->resolver->setDefault('foo', 42);560 $this->resolver->setAllowedValues('foo', '42');561 $this->resolver->resolve();562 }563 public function testResolveSucceedsIfValidValue()564 {565 $this->resolver->setDefault('foo', 'bar');566 $this->resolver->setAllowedValues('foo', 'bar');567 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());568 }569 /**570 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException571 * @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.572 */573 public function testResolveFailsIfInvalidValueMultiple()574 {575 $this->resolver->setDefault('foo', 42);576 $this->resolver->setAllowedValues('foo', array('bar', false, null));577 $this->resolver->resolve();578 }579 public function testResolveSucceedsIfValidValueMultiple()580 {581 $this->resolver->setDefault('foo', 'baz');582 $this->resolver->setAllowedValues('foo', array('bar', 'baz'));583 $this->assertEquals(array('foo' => 'baz'), $this->resolver->resolve());584 }585 public function testResolveFailsIfClosureReturnsFalse()586 {587 $this->resolver->setDefault('foo', 42);588 $this->resolver->setAllowedValues('foo', function ($value) use (&$passedValue) {589 $passedValue = $value;590 return false;591 });592 try {593 $this->resolver->resolve();594 $this->fail('Should fail');595 } catch (InvalidOptionsException $e) {596 }597 $this->assertSame(42, $passedValue);598 }599 public function testResolveSucceedsIfClosureReturnsTrue()600 {601 $this->resolver->setDefault('foo', 'bar');602 $this->resolver->setAllowedValues('foo', function ($value) use (&$passedValue) {603 $passedValue = $value;604 return true;605 });606 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());607 $this->assertSame('bar', $passedValue);608 }609 /**610 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException611 */612 public function testResolveFailsIfAllClosuresReturnFalse()613 {614 $this->resolver->setDefault('foo', 42);615 $this->resolver->setAllowedValues('foo', array(616 function () { return false; },617 function () { return false; },618 function () { return false; },619 ));620 $this->resolver->resolve();621 }622 public function testResolveSucceedsIfAnyClosureReturnsTrue()623 {624 $this->resolver->setDefault('foo', 'bar');625 $this->resolver->setAllowedValues('foo', array(626 function () { return false; },627 function () { return true; },628 function () { return false; },629 ));630 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());631 }632 ////////////////////////////////////////////////////////////////////////////633 // addAllowedValues()634 ////////////////////////////////////////////////////////////////////////////635 /**636 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException637 */638 public function testAddAllowedValuesFailsIfUnknownOption()639 {640 $this->resolver->addAllowedValues('foo', 'bar');641 }642 /**643 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException644 */645 public function testFailIfAddAllowedValuesFromLazyOption()646 {647 $this->resolver->setDefault('foo', function (Options $options) {648 $options->addAllowedValues('bar', 'baz');649 });650 $this->resolver->setDefault('bar', 'baz');651 $this->resolver->resolve();652 }653 /**654 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException655 */656 public function testResolveFailsIfInvalidAddedValue()657 {658 $this->resolver->setDefault('foo', 42);659 $this->resolver->addAllowedValues('foo', 'bar');660 $this->resolver->resolve();661 }662 public function testResolveSucceedsIfValidAddedValue()663 {664 $this->resolver->setDefault('foo', 'bar');665 $this->resolver->addAllowedValues('foo', 'bar');666 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());667 }668 /**669 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException670 */671 public function testResolveFailsIfInvalidAddedValueMultiple()672 {673 $this->resolver->setDefault('foo', 42);674 $this->resolver->addAllowedValues('foo', array('bar', 'baz'));675 $this->resolver->resolve();676 }677 public function testResolveSucceedsIfValidAddedValueMultiple()678 {679 $this->resolver->setDefault('foo', 'bar');680 $this->resolver->addAllowedValues('foo', array('bar', 'baz'));681 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());682 }683 public function testAddAllowedValuesDoesNotOverwrite()684 {685 $this->resolver->setDefault('foo', 'bar');686 $this->resolver->setAllowedValues('foo', 'bar');687 $this->resolver->addAllowedValues('foo', 'baz');688 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());689 }690 public function testAddAllowedValuesDoesNotOverwrite2()691 {692 $this->resolver->setDefault('foo', 'baz');693 $this->resolver->setAllowedValues('foo', 'bar');694 $this->resolver->addAllowedValues('foo', 'baz');695 $this->assertEquals(array('foo' => 'baz'), $this->resolver->resolve());696 }697 /**698 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException699 */700 public function testResolveFailsIfAllAddedClosuresReturnFalse()701 {702 $this->resolver->setDefault('foo', 42);703 $this->resolver->setAllowedValues('foo', function () { return false; });704 $this->resolver->addAllowedValues('foo', function () { return false; });705 $this->resolver->resolve();706 }707 public function testResolveSucceedsIfAnyAddedClosureReturnsTrue()708 {709 $this->resolver->setDefault('foo', 'bar');710 $this->resolver->setAllowedValues('foo', function () { return false; });711 $this->resolver->addAllowedValues('foo', function () { return true; });712 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());713 }714 public function testResolveSucceedsIfAnyAddedClosureReturnsTrue2()715 {716 $this->resolver->setDefault('foo', 'bar');717 $this->resolver->setAllowedValues('foo', function () { return true; });718 $this->resolver->addAllowedValues('foo', function () { return false; });719 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());720 }721 ////////////////////////////////////////////////////////////////////////////722 // setNormalizer()723 ////////////////////////////////////////////////////////////////////////////724 public function testSetNormalizerReturnsThis()725 {726 $this->resolver->setDefault('foo', 'bar');727 $this->assertSame($this->resolver, $this->resolver->setNormalizer('foo', function () {}));728 }729 public function testSetNormalizerClosure()730 {731 $this->resolver->setDefault('foo', 'bar');732 $this->resolver->setNormalizer('foo', function () {733 return 'normalized';734 });735 $this->assertEquals(array('foo' => 'normalized'), $this->resolver->resolve());736 }737 /**738 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException739 */740 public function testSetNormalizerFailsIfUnknownOption()741 {742 $this->resolver->setNormalizer('foo', function () {});743 }744 /**745 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException746 */747 public function testFailIfSetNormalizerFromLazyOption()748 {749 $this->resolver->setDefault('foo', function (Options $options) {750 $options->setNormalizer('foo', function () {});751 });752 $this->resolver->setDefault('bar', 'baz');753 $this->resolver->resolve();754 }755 public function testNormalizerReceivesSetOption()756 {757 $this->resolver->setDefault('foo', 'bar');758 $this->resolver->setNormalizer('foo', function (Options $options, $value) {759 return 'normalized['.$value.']';760 });761 $this->assertEquals(array('foo' => 'normalized[bar]'), $this->resolver->resolve());762 }763 public function testNormalizerReceivesPassedOption()764 {765 $this->resolver->setDefault('foo', 'bar');766 $this->resolver->setNormalizer('foo', function (Options $options, $value) {767 return 'normalized['.$value.']';768 });769 $resolved = $this->resolver->resolve(array('foo' => 'baz'));770 $this->assertEquals(array('foo' => 'normalized[baz]'), $resolved);771 }772 /**773 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException774 */775 public function testValidateTypeBeforeNormalization()776 {777 $this->resolver->setDefault('foo', 'bar');778 $this->resolver->setAllowedTypes('foo', 'int');779 $this->resolver->setNormalizer('foo', function () {780 \PHPUnit_Framework_Assert::fail('Should not be called.');781 });782 $this->resolver->resolve();783 }784 /**785 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException786 */787 public function testValidateValueBeforeNormalization()788 {789 $this->resolver->setDefault('foo', 'bar');790 $this->resolver->setAllowedValues('foo', 'baz');791 $this->resolver->setNormalizer('foo', function () {792 \PHPUnit_Framework_Assert::fail('Should not be called.');793 });794 $this->resolver->resolve();795 }796 public function testNormalizerCanAccessOtherOptions()797 {798 $this->resolver->setDefault('default', 'bar');799 $this->resolver->setDefault('norm', 'baz');800 $this->resolver->setNormalizer('norm', function (Options $options) {801 /* @var \PHPUnit_Framework_TestCase $test */802 \PHPUnit_Framework_Assert::assertSame('bar', $options['default']);803 return 'normalized';804 });805 $this->assertEquals(array(806 'default' => 'bar',807 'norm' => 'normalized',808 ), $this->resolver->resolve());809 }810 public function testNormalizerCanAccessLazyOptions()811 {812 $this->resolver->setDefault('lazy', function (Options $options) {813 return 'bar';814 });815 $this->resolver->setDefault('norm', 'baz');816 $this->resolver->setNormalizer('norm', function (Options $options) {817 /* @var \PHPUnit_Framework_TestCase $test */818 \PHPUnit_Framework_Assert::assertEquals('bar', $options['lazy']);819 return 'normalized';820 });821 $this->assertEquals(array(822 'lazy' => 'bar',823 'norm' => 'normalized',824 ), $this->resolver->resolve());825 }826 /**827 * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException828 */829 public function testFailIfCyclicDependencyBetweenNormalizers()830 {831 $this->resolver->setDefault('norm1', 'bar');832 $this->resolver->setDefault('norm2', 'baz');833 $this->resolver->setNormalizer('norm1', function (Options $options) {834 $options['norm2'];835 });836 $this->resolver->setNormalizer('norm2', function (Options $options) {837 $options['norm1'];838 });839 $this->resolver->resolve();840 }841 /**842 * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException843 */844 public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption()845 {846 $this->resolver->setDefault('lazy', function (Options $options) {847 $options['norm'];848 });849 $this->resolver->setDefault('norm', 'baz');850 $this->resolver->setNormalizer('norm', function (Options $options) {851 $options['lazy'];852 });853 $this->resolver->resolve();854 }855 public function testInvokeEachNormalizerOnlyOnce()856 {857 $calls = 0;858 $this->resolver->setDefault('norm1', 'bar');859 $this->resolver->setDefault('norm2', 'baz');860 $this->resolver->setNormalizer('norm1', function ($options) use (&$calls) {861 \PHPUnit_Framework_Assert::assertSame(1, ++$calls);862 $options['norm2'];863 });864 $this->resolver->setNormalizer('norm2', function () use (&$calls) {865 \PHPUnit_Framework_Assert::assertSame(2, ++$calls);866 });867 $this->resolver->resolve();868 $this->assertSame(2, $calls);869 }870 public function testNormalizerNotCalledForUnsetOptions()871 {872 $this->resolver->setDefined('norm');873 $this->resolver->setNormalizer('norm', function () {874 \PHPUnit_Framework_Assert::fail('Should not be called.');875 });876 $this->assertEmpty($this->resolver->resolve());877 }878 ////////////////////////////////////////////////////////////////////////////879 // setDefaults()880 ////////////////////////////////////////////////////////////////////////////881 public function testSetDefaultsReturnsThis()882 {883 $this->assertSame($this->resolver, $this->resolver->setDefaults(array('foo', 'bar')));884 }885 public function testSetDefaults()886 {887 $this->resolver->setDefault('one', '1');888 $this->resolver->setDefault('two', 'bar');889 $this->resolver->setDefaults(array(890 'two' => '2',891 'three' => '3',892 ));893 $this->assertEquals(array(894 'one' => '1',895 'two' => '2',896 'three' => '3',897 ), $this->resolver->resolve());898 }899 /**900 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException901 */902 public function testFailIfSetDefaultsFromLazyOption()903 {904 $this->resolver->setDefault('foo', function (Options $options) {905 $options->setDefaults(array('two' => '2'));906 });907 $this->resolver->resolve();908 }909 ////////////////////////////////////////////////////////////////////////////910 // remove()911 ////////////////////////////////////////////////////////////////////////////912 public function testRemoveReturnsThis()913 {914 $this->resolver->setDefault('foo', 'bar');915 $this->assertSame($this->resolver, $this->resolver->remove('foo'));916 }917 public function testRemoveSingleOption()918 {919 $this->resolver->setDefault('foo', 'bar');920 $this->resolver->setDefault('baz', 'boo');921 $this->resolver->remove('foo');922 $this->assertSame(array('baz' => 'boo'), $this->resolver->resolve());923 }924 public function testRemoveMultipleOptions()925 {926 $this->resolver->setDefault('foo', 'bar');927 $this->resolver->setDefault('baz', 'boo');928 $this->resolver->setDefault('doo', 'dam');929 $this->resolver->remove(array('foo', 'doo'));930 $this->assertSame(array('baz' => 'boo'), $this->resolver->resolve());931 }932 public function testRemoveLazyOption()933 {934 $this->resolver->setDefault('foo', function (Options $options) {935 return 'lazy';936 });937 $this->resolver->remove('foo');938 $this->assertSame(array(), $this->resolver->resolve());939 }940 public function testRemoveNormalizer()941 {942 $this->resolver->setDefault('foo', 'bar');943 $this->resolver->setNormalizer('foo', function (Options $options, $value) {944 return 'normalized';945 });946 $this->resolver->remove('foo');947 $this->resolver->setDefault('foo', 'bar');948 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());949 }950 public function testRemoveAllowedTypes()951 {952 $this->resolver->setDefault('foo', 'bar');953 $this->resolver->setAllowedTypes('foo', 'int');954 $this->resolver->remove('foo');955 $this->resolver->setDefault('foo', 'bar');956 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());957 }958 public function testRemoveAllowedValues()959 {960 $this->resolver->setDefault('foo', 'bar');961 $this->resolver->setAllowedValues('foo', array('baz', 'boo'));962 $this->resolver->remove('foo');963 $this->resolver->setDefault('foo', 'bar');964 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());965 }966 /**967 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException968 */969 public function testFailIfRemoveFromLazyOption()970 {971 $this->resolver->setDefault('foo', function (Options $options) {972 $options->remove('bar');973 });974 $this->resolver->setDefault('bar', 'baz');975 $this->resolver->resolve();976 }977 public function testRemoveUnknownOptionIgnored()978 {979 $this->assertNotNull($this->resolver->remove('foo'));980 }981 ////////////////////////////////////////////////////////////////////////////982 // clear()983 ////////////////////////////////////////////////////////////////////////////984 public function testClearReturnsThis()985 {986 $this->assertSame($this->resolver, $this->resolver->clear());987 }988 public function testClearRemovesAllOptions()989 {990 $this->resolver->setDefault('one', 1);991 $this->resolver->setDefault('two', 2);992 $this->resolver->clear();993 $this->assertEmpty($this->resolver->resolve());994 }995 public function testClearLazyOption()996 {997 $this->resolver->setDefault('foo', function (Options $options) {998 return 'lazy';999 });1000 $this->resolver->clear();1001 $this->assertSame(array(), $this->resolver->resolve());1002 }1003 public function testClearNormalizer()1004 {1005 $this->resolver->setDefault('foo', 'bar');1006 $this->resolver->setNormalizer('foo', function (Options $options, $value) {1007 return 'normalized';1008 });1009 $this->resolver->clear();1010 $this->resolver->setDefault('foo', 'bar');1011 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1012 }1013 public function testClearAllowedTypes()1014 {1015 $this->resolver->setDefault('foo', 'bar');1016 $this->resolver->setAllowedTypes('foo', 'int');1017 $this->resolver->clear();1018 $this->resolver->setDefault('foo', 'bar');1019 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1020 }1021 public function testClearAllowedValues()1022 {1023 $this->resolver->setDefault('foo', 'bar');1024 $this->resolver->setAllowedValues('foo', 'baz');1025 $this->resolver->clear();1026 $this->resolver->setDefault('foo', 'bar');1027 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1028 }1029 /**1030 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1031 */1032 public function testFailIfClearFromLazyption()1033 {1034 $this->resolver->setDefault('foo', function (Options $options) {1035 $options->clear();1036 });1037 $this->resolver->setDefault('bar', 'baz');1038 $this->resolver->resolve();1039 }1040 public function testClearOptionAndNormalizer()1041 {1042 $this->resolver->setDefault('foo1', 'bar');1043 $this->resolver->setNormalizer('foo1', function (Options $options) {1044 return '';1045 });1046 $this->resolver->setDefault('foo2', 'bar');1047 $this->resolver->setNormalizer('foo2', function (Options $options) {1048 return '';1049 });1050 $this->resolver->clear();1051 $this->assertEmpty($this->resolver->resolve());1052 }1053 ////////////////////////////////////////////////////////////////////////////1054 // ArrayAccess1055 ////////////////////////////////////////////////////////////////////////////1056 public function testArrayAccess()1057 {1058 $this->resolver->setDefault('default1', 0);1059 $this->resolver->setDefault('default2', 1);1060 $this->resolver->setRequired('required');1061 $this->resolver->setDefined('defined');1062 $this->resolver->setDefault('lazy1', function (Options $options) {1063 return 'lazy';1064 });1065 $this->resolver->setDefault('lazy2', function (Options $options) {1066 \PHPUnit_Framework_Assert::assertTrue(isset($options['default1']));1067 \PHPUnit_Framework_Assert::assertTrue(isset($options['default2']));1068 \PHPUnit_Framework_Assert::assertTrue(isset($options['required']));1069 \PHPUnit_Framework_Assert::assertTrue(isset($options['lazy1']));1070 \PHPUnit_Framework_Assert::assertTrue(isset($options['lazy2']));1071 \PHPUnit_Framework_Assert::assertFalse(isset($options['defined']));1072 \PHPUnit_Framework_Assert::assertSame(0, $options['default1']);1073 \PHPUnit_Framework_Assert::assertSame(42, $options['default2']);1074 \PHPUnit_Framework_Assert::assertSame('value', $options['required']);1075 \PHPUnit_Framework_Assert::assertSame('lazy', $options['lazy1']);1076 // Obviously $options['lazy'] and $options['defined'] cannot be1077 // accessed1078 });1079 $this->resolver->resolve(array('default2' => 42, 'required' => 'value'));1080 }1081 /**1082 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1083 */1084 public function testArrayAccessGetFailsOutsideResolve()1085 {1086 $this->resolver->setDefault('default', 0);1087 $this->resolver['default'];1088 }1089 /**1090 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1091 */1092 public function testArrayAccessExistsFailsOutsideResolve()1093 {1094 $this->resolver->setDefault('default', 0);1095 isset($this->resolver['default']);1096 }1097 /**1098 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1099 */1100 public function testArrayAccessSetNotSupported()1101 {1102 $this->resolver['default'] = 0;1103 }1104 /**1105 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1106 */1107 public function testArrayAccessUnsetNotSupported()1108 {1109 $this->resolver->setDefault('default', 0);1110 unset($this->resolver['default']);1111 }1112 /**1113 * @expectedException \Symfony\Component\OptionsResolver\Exception\NoSuchOptionException1114 * @expectedExceptionMessage The option "undefined" does not exist. Known options are: "foo", "lazy".1115 */1116 public function testFailIfGetNonExisting()1117 {1118 $this->resolver->setDefault('foo', 'bar');1119 $this->resolver->setDefault('lazy', function (Options $options) {1120 $options['undefined'];1121 });1122 $this->resolver->resolve();1123 }1124 /**1125 * @expectedException \Symfony\Component\OptionsResolver\Exception\NoSuchOptionException1126 * @expectedExceptionMessage The optional option "defined" has no value set. You should make sure it is set with "isset" before reading it.1127 */1128 public function testFailIfGetDefinedButUnset()1129 {1130 $this->resolver->setDefined('defined');1131 $this->resolver->setDefault('lazy', function (Options $options) {1132 $options['defined'];1133 });1134 $this->resolver->resolve();1135 }1136 /**1137 * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException1138 */1139 public function testFailIfCyclicDependency()1140 {1141 $this->resolver->setDefault('lazy1', function (Options $options) {1142 $options['lazy2'];1143 });1144 $this->resolver->setDefault('lazy2', function (Options $options) {1145 $options['lazy1'];1146 });1147 $this->resolver->resolve();1148 }1149 ////////////////////////////////////////////////////////////////////////////1150 // Countable1151 ////////////////////////////////////////////////////////////////////////////1152 public function testCount()1153 {1154 $this->resolver->setDefault('default', 0);1155 $this->resolver->setRequired('required');1156 $this->resolver->setDefined('defined');1157 $this->resolver->setDefault('lazy1', function () {});1158 $this->resolver->setDefault('lazy2', function (Options $options) {1159 \PHPUnit_Framework_Assert::assertCount(4, $options);1160 });1161 $this->assertCount(4, $this->resolver->resolve(array('required' => 'value')));1162 }1163 /**1164 * In resolve() we count the options that are actually set (which may be1165 * only a subset of the defined options). Outside of resolve(), it's not1166 * clear what is counted.1167 *1168 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1169 */1170 public function testCountFailsOutsideResolve()1171 {1172 $this->resolver->setDefault('foo', 0);1173 $this->resolver->setRequired('bar');1174 $this->resolver->setDefined('bar');1175 $this->resolver->setDefault('lazy1', function () {});1176 count($this->resolver);1177 }1178}...

Full Screen

Full Screen

OptionsResolverTest.php

Source:OptionsResolverTest.php Github

copy

Full Screen

...17{18 /**19 * @var OptionsResolver20 */21 private $resolver;22 protected function setUp()23 {24 $this->resolver = new OptionsResolver();25 }26 public function testResolve()27 {28 $this->resolver->setDefaults(array(29 'one' => '1',30 'two' => '2',31 ));32 $options = array(33 'two' => '20',34 );35 $this->assertEquals(array(36 'one' => '1',37 'two' => '20',38 ), $this->resolver->resolve($options));39 }40 public function testResolveNumericOptions()41 {42 $this->resolver->setDefaults(array(43 '1' => '1',44 '2' => '2',45 ));46 $options = array(47 '2' => '20',48 );49 $this->assertEquals(array(50 '1' => '1',51 '2' => '20',52 ), $this->resolver->resolve($options));53 }54 public function testResolveLazy()55 {56 $this->resolver->setDefaults(array(57 'one' => '1',58 'two' => function (Options $options) {59 return '20';60 },61 ));62 $this->assertEquals(array(63 'one' => '1',64 'two' => '20',65 ), $this->resolver->resolve(array()));66 }67 public function testResolveLazyDependencyOnOptional()68 {69 $this->resolver->setDefaults(array(70 'one' => '1',71 'two' => function (Options $options) {72 return $options['one'].'2';73 },74 ));75 $options = array(76 'one' => '10',77 );78 $this->assertEquals(array(79 'one' => '10',80 'two' => '102',81 ), $this->resolver->resolve($options));82 }83 public function testResolveLazyDependencyOnMissingOptionalWithoutDefault()84 {85 $test = $this;86 $this->resolver->setOptional(array(87 'one',88 ));89 $this->resolver->setDefaults(array(90 'two' => function (Options $options) use ($test) {91 /* @var \PHPUnit_Framework_TestCase $test */92 $test->assertFalse(isset($options['one']));93 return '2';94 },95 ));96 $options = array();97 $this->assertEquals(array(98 'two' => '2',99 ), $this->resolver->resolve($options));100 }101 public function testResolveLazyDependencyOnOptionalWithoutDefault()102 {103 $test = $this;104 $this->resolver->setOptional(array(105 'one',106 ));107 $this->resolver->setDefaults(array(108 'two' => function (Options $options) use ($test) {109 /* @var \PHPUnit_Framework_TestCase $test */110 $test->assertTrue(isset($options['one']));111 return $options['one'].'2';112 },113 ));114 $options = array(115 'one' => '10',116 );117 $this->assertEquals(array(118 'one' => '10',119 'two' => '102',120 ), $this->resolver->resolve($options));121 }122 public function testResolveLazyDependencyOnRequired()123 {124 $this->resolver->setRequired(array(125 'one',126 ));127 $this->resolver->setDefaults(array(128 'two' => function (Options $options) {129 return $options['one'].'2';130 },131 ));132 $options = array(133 'one' => '10',134 );135 $this->assertEquals(array(136 'one' => '10',137 'two' => '102',138 ), $this->resolver->resolve($options));139 }140 public function testResolveLazyReplaceDefaults()141 {142 $test = $this;143 $this->resolver->setDefaults(array(144 'one' => function (Options $options) use ($test) {145 /* @var \PHPUnit_Framework_TestCase $test */146 $test->fail('Previous closure should not be executed');147 },148 ));149 $this->resolver->replaceDefaults(array(150 'one' => function (Options $options, $previousValue) {151 return '1';152 },153 ));154 $this->assertEquals(array(155 'one' => '1',156 ), $this->resolver->resolve(array()));157 }158 /**159 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException160 */161 public function testResolveFailsIfNonExistingOption()162 {163 $this->resolver->setDefaults(array(164 'one' => '1',165 ));166 $this->resolver->setRequired(array(167 'two',168 ));169 $this->resolver->setOptional(array(170 'three',171 ));172 $this->resolver->resolve(array(173 'foo' => 'bar',174 ));175 }176 /**177 * @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException178 */179 public function testResolveFailsIfMissingRequiredOption()180 {181 $this->resolver->setRequired(array(182 'one',183 ));184 $this->resolver->setDefaults(array(185 'two' => '2',186 ));187 $this->resolver->resolve(array(188 'two' => '20',189 ));190 }191 public function testResolveSucceedsIfOptionValueAllowed()192 {193 $this->resolver->setDefaults(array(194 'one' => '1',195 ));196 $this->resolver->setAllowedValues(array(197 'one' => array('1', 'one'),198 ));199 $options = array(200 'one' => 'one',201 );202 $this->assertEquals(array(203 'one' => 'one',204 ), $this->resolver->resolve($options));205 }206 public function testResolveSucceedsIfOptionValueAllowed2()207 {208 $this->resolver->setDefaults(array(209 'one' => '1',210 'two' => '2',211 ));212 $this->resolver->setAllowedValues(array(213 'one' => '1',214 'two' => '2',215 ));216 $this->resolver->addAllowedValues(array(217 'one' => 'one',218 'two' => 'two',219 ));220 $options = array(221 'one' => '1',222 'two' => 'two',223 );224 $this->assertEquals(array(225 'one' => '1',226 'two' => 'two',227 ), $this->resolver->resolve($options));228 }229 public function testResolveSucceedsIfOptionalWithAllowedValuesNotSet()230 {231 $this->resolver->setRequired(array(232 'one',233 ));234 $this->resolver->setOptional(array(235 'two',236 ));237 $this->resolver->setAllowedValues(array(238 'one' => array('1', 'one'),239 'two' => array('2', 'two'),240 ));241 $options = array(242 'one' => '1',243 );244 $this->assertEquals(array(245 'one' => '1',246 ), $this->resolver->resolve($options));247 }248 /**249 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException250 */251 public function testResolveFailsIfOptionValueNotAllowed()252 {253 $this->resolver->setDefaults(array(254 'one' => '1',255 ));256 $this->resolver->setAllowedValues(array(257 'one' => array('1', 'one'),258 ));259 $this->resolver->resolve(array(260 'one' => '2',261 ));262 }263 public function testResolveSucceedsIfOptionTypeAllowed()264 {265 $this->resolver->setDefaults(array(266 'one' => '1',267 ));268 $this->resolver->setAllowedTypes(array(269 'one' => 'string',270 ));271 $options = array(272 'one' => 'one',273 );274 $this->assertEquals(array(275 'one' => 'one',276 ), $this->resolver->resolve($options));277 }278 public function testResolveSucceedsIfOptionTypeAllowedPassArray()279 {280 $this->resolver->setDefaults(array(281 'one' => '1',282 ));283 $this->resolver->setAllowedTypes(array(284 'one' => array('string', 'bool'),285 ));286 $options = array(287 'one' => true,288 );289 $this->assertEquals(array(290 'one' => true,291 ), $this->resolver->resolve($options));292 }293 public function testResolveSucceedsIfOptionTypeAllowedPassObject()294 {295 $this->resolver->setDefaults(array(296 'one' => '1',297 ));298 $this->resolver->setAllowedTypes(array(299 'one' => 'object',300 ));301 $object = new \stdClass();302 $options = array(303 'one' => $object,304 );305 $this->assertEquals(array(306 'one' => $object,307 ), $this->resolver->resolve($options));308 }309 public function testResolveSucceedsIfOptionTypeAllowedPassClass()310 {311 $this->resolver->setDefaults(array(312 'one' => '1',313 ));314 $this->resolver->setAllowedTypes(array(315 'one' => '\stdClass',316 ));317 $object = new \stdClass();318 $options = array(319 'one' => $object,320 );321 $this->assertEquals(array(322 'one' => $object,323 ), $this->resolver->resolve($options));324 }325 public function testResolveSucceedsIfOptionTypeAllowedAddTypes()326 {327 $this->resolver->setDefaults(array(328 'one' => '1',329 'two' => '2',330 ));331 $this->resolver->setAllowedTypes(array(332 'one' => 'string',333 'two' => 'bool',334 ));335 $this->resolver->addAllowedTypes(array(336 'one' => 'float',337 'two' => 'integer',338 ));339 $options = array(340 'one' => 1.23,341 'two' => false,342 );343 $this->assertEquals(array(344 'one' => 1.23,345 'two' => false,346 ), $this->resolver->resolve($options));347 }348 public function testResolveSucceedsIfOptionalWithTypeAndWithoutValue()349 {350 $this->resolver->setOptional(array(351 'one',352 'two',353 ));354 $this->resolver->setAllowedTypes(array(355 'one' => 'string',356 'two' => 'int',357 ));358 $options = array(359 'two' => 1,360 );361 $this->assertEquals(array(362 'two' => 1,363 ), $this->resolver->resolve($options));364 }365 /**366 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException367 */368 public function testResolveFailsIfOptionTypeNotAllowed()369 {370 $this->resolver->setDefaults(array(371 'one' => '1',372 ));373 $this->resolver->setAllowedTypes(array(374 'one' => array('string', 'bool'),375 ));376 $this->resolver->resolve(array(377 'one' => 1.23,378 ));379 }380 /**381 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException382 */383 public function testResolveFailsIfOptionTypeNotAllowedMultipleOptions()384 {385 $this->resolver->setDefaults(array(386 'one' => '1',387 'two' => '2',388 ));389 $this->resolver->setAllowedTypes(array(390 'one' => 'string',391 'two' => 'bool',392 ));393 $this->resolver->resolve(array(394 'one' => 'foo',395 'two' => 1.23,396 ));397 }398 /**399 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException400 */401 public function testResolveFailsIfOptionTypeNotAllowedAddTypes()402 {403 $this->resolver->setDefaults(array(404 'one' => '1',405 ));406 $this->resolver->setAllowedTypes(array(407 'one' => 'string',408 ));409 $this->resolver->addAllowedTypes(array(410 'one' => 'bool',411 ));412 $this->resolver->resolve(array(413 'one' => 1.23,414 ));415 }416 public function testFluidInterface()417 {418 $this->resolver->setDefaults(array('one' => '1'))419 ->replaceDefaults(array('one' => '2'))420 ->setAllowedValues(array('one' => array('1', '2')))421 ->addAllowedValues(array('one' => array('3')))422 ->setRequired(array('two'))423 ->setOptional(array('three'));424 $options = array(425 'two' => '2',426 );427 $this->assertEquals(array(428 'one' => '2',429 'two' => '2',430 ), $this->resolver->resolve($options));431 }432 public function testKnownIfDefaultWasSet()433 {434 $this->assertFalse($this->resolver->isKnown('foo'));435 $this->resolver->setDefaults(array(436 'foo' => 'bar',437 ));438 $this->assertTrue($this->resolver->isKnown('foo'));439 }440 public function testKnownIfRequired()441 {442 $this->assertFalse($this->resolver->isKnown('foo'));443 $this->resolver->setRequired(array(444 'foo',445 ));446 $this->assertTrue($this->resolver->isKnown('foo'));447 }448 public function testKnownIfOptional()449 {450 $this->assertFalse($this->resolver->isKnown('foo'));451 $this->resolver->setOptional(array(452 'foo',453 ));454 $this->assertTrue($this->resolver->isKnown('foo'));455 }456 public function testRequiredIfRequired()457 {458 $this->assertFalse($this->resolver->isRequired('foo'));459 $this->resolver->setRequired(array(460 'foo',461 ));462 $this->assertTrue($this->resolver->isRequired('foo'));463 }464 public function testNormalizersTransformFinalOptions()465 {466 $this->resolver->setDefaults(array(467 'foo' => 'bar',468 'bam' => 'baz',469 ));470 $this->resolver->setNormalizers(array(471 'foo' => function (Options $options, $value) {472 return $options['bam'].'['.$value.']';473 },474 ));475 $expected = array(476 'foo' => 'baz[bar]',477 'bam' => 'baz',478 );479 $this->assertEquals($expected, $this->resolver->resolve(array()));480 $expected = array(481 'foo' => 'boo[custom]',482 'bam' => 'boo',483 );484 $this->assertEquals($expected, $this->resolver->resolve(array(485 'foo' => 'custom',486 'bam' => 'boo',487 )));488 }489 public function testResolveWithoutOptionSucceedsIfRequiredAndDefaultValue()490 {491 $this->resolver->setRequired(array(492 'foo',493 ));494 $this->resolver->setDefaults(array(495 'foo' => 'bar',496 ));497 $this->assertEquals(array(498 'foo' => 'bar',499 ), $this->resolver->resolve(array()));500 }501 public function testResolveWithoutOptionSucceedsIfDefaultValueAndRequired()502 {503 $this->resolver->setDefaults(array(504 'foo' => 'bar',505 ));506 $this->resolver->setRequired(array(507 'foo',508 ));509 $this->assertEquals(array(510 'foo' => 'bar',511 ), $this->resolver->resolve(array()));512 }513 public function testResolveSucceedsIfOptionRequiredAndValueAllowed()514 {515 $this->resolver->setRequired(array(516 'one', 'two',517 ));518 $this->resolver->setAllowedValues(array(519 'two' => array('2'),520 ));521 $options = array(522 'one' => '1',523 'two' => '2',524 );525 $this->assertEquals($options, $this->resolver->resolve($options));526 }527 public function testResolveSucceedsIfValueAllowedCallbackReturnsTrue()528 {529 $this->resolver->setRequired(array(530 'test',531 ));532 $this->resolver->setAllowedValues(array(533 'test' => function ($value) {534 return true;535 },536 ));537 $options = array(538 'test' => true,539 );540 $this->assertEquals($options, $this->resolver->resolve($options));541 }542 /**543 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException544 */545 public function testResolveFailsIfValueAllowedCallbackReturnsFalse()546 {547 $this->resolver->setRequired(array(548 'test',549 ));550 $this->resolver->setAllowedValues(array(551 'test' => function ($value) {552 return false;553 },554 ));555 $options = array(556 'test' => true,557 );558 $this->assertEquals($options, $this->resolver->resolve($options));559 }560 public function testClone()561 {562 $this->resolver->setDefaults(array('one' => '1'));563 $clone = clone $this->resolver;564 // Changes after cloning don't affect each other565 $this->resolver->setDefaults(array('two' => '2'));566 $clone->setDefaults(array('three' => '3'));567 $this->assertEquals(array(568 'one' => '1',569 'two' => '2',570 ), $this->resolver->resolve());571 $this->assertEquals(array(572 'one' => '1',573 'three' => '3',574 ), $clone->resolve());575 }576}...

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1$resolver = new Resolver();2echo $resolver->resolve("1.php");3$resolver = new Resolver();4echo $resolver->resolve("2.php");5$resolver = new Resolver();6echo $resolver->resolve("3.php");7$resolver = new Resolver();8echo $resolver->resolve("4.php");9$resolver = new Resolver();10echo $resolver->resolve("5.php");11$resolver = new Resolver();12echo $resolver->resolve("6.php");13$resolver = new Resolver();14echo $resolver->resolve("7.php");15$resolver = new Resolver();16echo $resolver->resolve("8.php");17$resolver = new Resolver();18echo $resolver->resolve("9.php");19$resolver = new Resolver();20echo $resolver->resolve("10.php");21$resolver = new Resolver();22echo $resolver->resolve("11.php");23$resolver = new Resolver();24echo $resolver->resolve("12.php");25$resolver = new Resolver();26echo $resolver->resolve("13.php");27$resolver = new Resolver();28echo $resolver->resolve("14.php");29$resolver = new Resolver();30echo $resolver->resolve("15.php");31$resolver = new Resolver();32echo $resolver->resolve("16.php");

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1$resolver = new Resolver();2echo $resolver->resolve('1.php');3$resolver = new Resolver();4echo $resolver->resolve('2.php');5$resolver = new Resolver();6echo $resolver->resolve('3.php');7$resolver = new Resolver();8echo $resolver->resolve('4.php');9$resolver = new Resolver();10echo $resolver->resolve('5.php');11$resolver = new Resolver();12echo $resolver->resolve('6.php');13$resolver = new Resolver();14echo $resolver->resolve('7.php');15$resolver = new Resolver();16echo $resolver->resolve('8.php');17$resolver = new Resolver();18echo $resolver->resolve('9.php');19$resolver = new Resolver();20echo $resolver->resolve('10.php');21$resolver = new Resolver();22echo $resolver->resolve('11.php');23$resolver = new Resolver();24echo $resolver->resolve('12.php');

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1$resolver = new Resolver();2$filePath = $resolver->resolve('1.php');3$resolver = new Resolver();4$filePath = $resolver->resolve('2.php');5$resolver = new Resolver();6$filePath = $resolver->resolve('3.php');7$resolver = new Resolver();8$filePath = $resolver->resolve('4.php');9$resolver = new Resolver();10$filePath = $resolver->resolve('5.php');11$resolver = new Resolver();12$filePath = $resolver->resolve('6.php');13$resolver = new Resolver();14$filePath = $resolver->resolve('7.php');15$resolver = new Resolver();16$filePath = $resolver->resolve('8.php');17$resolver = new Resolver();18$filePath = $resolver->resolve('9.php');19$resolver = new Resolver();20$filePath = $resolver->resolve('10.php');21$resolver = new Resolver();22$filePath = $resolver->resolve('11.php');23$resolver = new Resolver();24$filePath = $resolver->resolve('

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1 $resolver = new Resolver;2 $resolver->resolve('1.php');3 $resolver = new Resolver;4 $resolver->resolve('2.php');5 $resolver = new Resolver;6 $resolver->resolve('3.php');7 $resolver = new Resolver;8 $resolver->resolve('4.php');9 $resolver = new Resolver;10 $resolver->resolve('5.php');11 $resolver = new Resolver;12 $resolver->resolve('6.php');13 $resolver = new Resolver;14 $resolver->resolve('7.php');15 $resolver = new Resolver;16 $resolver->resolve('8.php');17 $resolver = new Resolver;18 $resolver->resolve('9.php');19 $resolver = new Resolver;20 $resolver->resolve('10.php');21 $resolver = new Resolver;22 $resolver->resolve('11.php');23 $resolver = new Resolver;24 $resolver->resolve('12.php');25 $resolver = new Resolver;26 $resolver->resolve('13.php');

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1$resolver = new Resolver();2$uri = $resolver->resolve('1.php');3echo $uri->getURL();4$resolver = new Resolver();5$uri = $resolver->resolve('/1.php');6echo $uri->getURL();7$resolver = new Resolver();8echo $uri->getURL();9$resolver = new Resolver();10echo $uri->getURL();11$resolver = new Resolver();12echo $uri->getURL();13$resolver = new Resolver();14echo $uri->getURL();15$resolver = new Resolver();16echo $uri->getURL();17$resolver = new Resolver();18echo $uri->getURL();19$resolver = new Resolver();20echo $uri->getURL();21$resolver = new Resolver();22echo $uri->getURL();23$resolver = new Resolver();24echo $uri->getURL();

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1$router = new Router();2$router->setResolver(new Resolver());3$router->addRoute(new Route('/test', 'testController'));4$router->addRoute(new Route('/test2', 'testController2'));5$router->addRoute(new Route('/test3', 'testController3'));6$router->addRoute(new Route('/test4', 'testController4'));7$router->addRoute(new Route('/test5', 'testController5'));8$router->addRoute(new Route('/test6', 'testController6'));9$router->addRoute(new Route('/test7', 'testController7'));10$router->addRoute(new Route('/test8', 'testController8'));11$router->addRoute(new Route('/test9', 'testController9'));12$router->addRoute(new Route('/test10', 'testController10'));13$router->addRoute(new Route('/test11', 'testController11'));14$router->addRoute(new Route('/test12', 'testController12'));15$router->addRoute(new Route('/test13', 'testController13'));16$router->addRoute(new Route('/test14', 'testController14'));17$router->addRoute(new Route('/test15', 'testController15'));18$router->addRoute(new Route('/test16', 'testController16'));19$router->addRoute(new Route('/test17', 'testController17'));20$router->addRoute(new Route('/test18', 'testController18'));21$router->addRoute(new Route('/test19', 'testController19'));22$router->addRoute(new Route('/test20', 'testController20'));23$router->addRoute(new Route('/test21', 'testController21'));24$router->addRoute(new Route('/test22', 'testController22'));25$router->addRoute(new Route('/test23', 'testController23'));26$router->addRoute(new Route('/test24', 'testController24'));27$router->addRoute(new Route('/test25', 'testController25'));28$router->addRoute(new Route('/test26', 'testController26'));29$router->addRoute(new Route('/test27', 'testController27'));30$router->addRoute(new Route('/test28', 'testController28'));31$router->addRoute(new Route('/test29', 'testController29'));32$router->addRoute(new Route('/test30', 'testController30'));33$router->addRoute(new

Full Screen

Full Screen

resolve

Using AI Code Generation

copy

Full Screen

1$uri->setQuery('controller=foo&module=bar');2$uri->setFragment('anchor');3$uri->setPath('1.php');4$uri->setPath('1.php');5$uri->setHost('www.example.com');6$uri->setPort(80);7$uri->setScheme('http');8$uri->setUser('user');9$uri->setPassword('pass');10$uri->setPath('1.php');11$uri->setQuery('controller=foo&module=bar');12$uri->setFragment('anchor');13$uri->setPath('1.php');14$uri->setPath('1.php');15$uri->setHost('www.example.com');16$uri->setPort(80);17$uri->setScheme('http');18$uri->setUser('user');19$uri->setPassword('pass');20$uri->setPath('1.php');21$uri->setQuery('controller=foo&module=bar');22$uri->setFragment('anchor');23$uri->setPath('1.php');24$uri->setPath('1.php');25$uri->setHost('www.example.com');26$uri->setPort(80);27$uri->setScheme('http');28$uri->setUser('user');29$uri->setPassword('pass');30$uri->setPath('1.php');31$uri->setQuery('controller=foo&module=bar');32$uri->setFragment('anchor');33$uri->setPath('1.php');34$uri->setPath('1.php');35$uri->setHost('www.example.com');36$uri->setPort(80);37$uri->setScheme('http');38$uri->setUser('user');39$uri->setPassword('pass');40$uri->setPath('1.php');41$uri->setQuery('controller=foo&module=bar');42$uri->setFragment('anchor');43$uri->setPath('1.php');44$uri->setPath('1.php');45$uri->setHost('www.example.com');46$uri->setPort(80);47$uri->setScheme('http');48$uri->setUser('user');49$uri->setPassword('pass');50$uri->setPath('1.php');51$uri->setQuery('controller=foo&module=bar');52$uri->setFragment('anchor');53$uri->setPath('1.php

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Atoum automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Trigger resolve code on LambdaTest Cloud Grid

Execute automation tests with resolve on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful