How to use resolver class

Best Atoum code snippet using resolver

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 ////////////////////////////////////////////////////////////////////////////27 // resolve()28 ////////////////////////////////////////////////////////////////////////////29 /**30 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException31 * @expectedExceptionMessage The option "foo" does not exist. Defined options are: "a", "z".32 */33 public function testResolveFailsIfNonExistingOption()34 {35 $this->resolver->setDefault('z', '1');36 $this->resolver->setDefault('a', '2');37 $this->resolver->resolve(array('foo' => 'bar'));38 }39 /**40 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException41 * @expectedExceptionMessage The options "baz", "foo", "ping" do not exist. Defined options are: "a", "z".42 */43 public function testResolveFailsIfMultipleNonExistingOptions()44 {45 $this->resolver->setDefault('z', '1');46 $this->resolver->setDefault('a', '2');47 $this->resolver->resolve(array('ping' => 'pong', 'foo' => 'bar', 'baz' => 'bam'));48 }49 /**50 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException51 */52 public function testResolveFailsFromLazyOption()53 {54 $this->resolver->setDefault('foo', function (Options $options) {55 $options->resolve(array());56 });57 $this->resolver->resolve();58 }59 ////////////////////////////////////////////////////////////////////////////60 // setDefault()/hasDefault()61 ////////////////////////////////////////////////////////////////////////////62 public function testSetDefaultReturnsThis()63 {64 $this->assertSame($this->resolver, $this->resolver->setDefault('foo', 'bar'));65 }66 public function testSetDefault()67 {68 $this->resolver->setDefault('one', '1');69 $this->resolver->setDefault('two', '20');70 $this->assertEquals(array(71 'one' => '1',72 'two' => '20',73 ), $this->resolver->resolve());74 }75 /**76 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException77 */78 public function testFailIfSetDefaultFromLazyOption()79 {80 $this->resolver->setDefault('lazy', function (Options $options) {81 $options->setDefault('default', 42);82 });83 $this->resolver->resolve();84 }85 public function testHasDefault()86 {87 $this->assertFalse($this->resolver->hasDefault('foo'));88 $this->resolver->setDefault('foo', 42);89 $this->assertTrue($this->resolver->hasDefault('foo'));90 }91 public function testHasDefaultWithNullValue()92 {93 $this->assertFalse($this->resolver->hasDefault('foo'));94 $this->resolver->setDefault('foo', null);95 $this->assertTrue($this->resolver->hasDefault('foo'));96 }97 ////////////////////////////////////////////////////////////////////////////98 // lazy setDefault()99 ////////////////////////////////////////////////////////////////////////////100 public function testSetLazyReturnsThis()101 {102 $this->assertSame($this->resolver, $this->resolver->setDefault('foo', function (Options $options) {}));103 }104 public function testSetLazyClosure()105 {106 $this->resolver->setDefault('foo', function (Options $options) {107 return 'lazy';108 });109 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());110 }111 public function testClosureWithoutTypeHintNotInvoked()112 {113 $closure = function ($options) {114 Assert::fail('Should not be called');115 };116 $this->resolver->setDefault('foo', $closure);117 $this->assertSame(array('foo' => $closure), $this->resolver->resolve());118 }119 public function testClosureWithoutParametersNotInvoked()120 {121 $closure = function () {122 Assert::fail('Should not be called');123 };124 $this->resolver->setDefault('foo', $closure);125 $this->assertSame(array('foo' => $closure), $this->resolver->resolve());126 }127 public function testAccessPreviousDefaultValue()128 {129 // defined by superclass130 $this->resolver->setDefault('foo', 'bar');131 // defined by subclass132 $this->resolver->setDefault('foo', function (Options $options, $previousValue) {133 Assert::assertEquals('bar', $previousValue);134 return 'lazy';135 });136 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());137 }138 public function testAccessPreviousLazyDefaultValue()139 {140 // defined by superclass141 $this->resolver->setDefault('foo', function (Options $options) {142 return 'bar';143 });144 // defined by subclass145 $this->resolver->setDefault('foo', function (Options $options, $previousValue) {146 Assert::assertEquals('bar', $previousValue);147 return 'lazy';148 });149 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());150 }151 public function testPreviousValueIsNotEvaluatedIfNoSecondArgument()152 {153 // defined by superclass154 $this->resolver->setDefault('foo', function () {155 Assert::fail('Should not be called');156 });157 // defined by subclass, no $previousValue argument defined!158 $this->resolver->setDefault('foo', function (Options $options) {159 return 'lazy';160 });161 $this->assertEquals(array('foo' => 'lazy'), $this->resolver->resolve());162 }163 public function testOverwrittenLazyOptionNotEvaluated()164 {165 $this->resolver->setDefault('foo', function (Options $options) {166 Assert::fail('Should not be called');167 });168 $this->resolver->setDefault('foo', 'bar');169 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());170 }171 public function testInvokeEachLazyOptionOnlyOnce()172 {173 $calls = 0;174 $this->resolver->setDefault('lazy1', function (Options $options) use (&$calls) {175 Assert::assertSame(1, ++$calls);176 $options['lazy2'];177 });178 $this->resolver->setDefault('lazy2', function (Options $options) use (&$calls) {179 Assert::assertSame(2, ++$calls);180 });181 $this->resolver->resolve();182 $this->assertSame(2, $calls);183 }184 ////////////////////////////////////////////////////////////////////////////185 // setRequired()/isRequired()/getRequiredOptions()186 ////////////////////////////////////////////////////////////////////////////187 public function testSetRequiredReturnsThis()188 {189 $this->assertSame($this->resolver, $this->resolver->setRequired('foo'));190 }191 /**192 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException193 */194 public function testFailIfSetRequiredFromLazyOption()195 {196 $this->resolver->setDefault('foo', function (Options $options) {197 $options->setRequired('bar');198 });199 $this->resolver->resolve();200 }201 /**202 * @expectedException \Symfony\Component\OptionsResolver\Exception\MissingOptionsException203 */204 public function testResolveFailsIfRequiredOptionMissing()205 {206 $this->resolver->setRequired('foo');207 $this->resolver->resolve();208 }209 public function testResolveSucceedsIfRequiredOptionSet()210 {211 $this->resolver->setRequired('foo');212 $this->resolver->setDefault('foo', 'bar');213 $this->assertNotEmpty($this->resolver->resolve());214 }215 public function testResolveSucceedsIfRequiredOptionPassed()216 {217 $this->resolver->setRequired('foo');218 $this->assertNotEmpty($this->resolver->resolve(array('foo' => 'bar')));219 }220 public function testIsRequired()221 {222 $this->assertFalse($this->resolver->isRequired('foo'));223 $this->resolver->setRequired('foo');224 $this->assertTrue($this->resolver->isRequired('foo'));225 }226 public function testRequiredIfSetBefore()227 {228 $this->assertFalse($this->resolver->isRequired('foo'));229 $this->resolver->setDefault('foo', 'bar');230 $this->resolver->setRequired('foo');231 $this->assertTrue($this->resolver->isRequired('foo'));232 }233 public function testStillRequiredAfterSet()234 {235 $this->assertFalse($this->resolver->isRequired('foo'));236 $this->resolver->setRequired('foo');237 $this->resolver->setDefault('foo', 'bar');238 $this->assertTrue($this->resolver->isRequired('foo'));239 }240 public function testIsNotRequiredAfterRemove()241 {242 $this->assertFalse($this->resolver->isRequired('foo'));243 $this->resolver->setRequired('foo');244 $this->resolver->remove('foo');245 $this->assertFalse($this->resolver->isRequired('foo'));246 }247 public function testIsNotRequiredAfterClear()248 {249 $this->assertFalse($this->resolver->isRequired('foo'));250 $this->resolver->setRequired('foo');251 $this->resolver->clear();252 $this->assertFalse($this->resolver->isRequired('foo'));253 }254 public function testGetRequiredOptions()255 {256 $this->resolver->setRequired(array('foo', 'bar'));257 $this->resolver->setDefault('bam', 'baz');258 $this->resolver->setDefault('foo', 'boo');259 $this->assertSame(array('foo', 'bar'), $this->resolver->getRequiredOptions());260 }261 ////////////////////////////////////////////////////////////////////////////262 // isMissing()/getMissingOptions()263 ////////////////////////////////////////////////////////////////////////////264 public function testIsMissingIfNotSet()265 {266 $this->assertFalse($this->resolver->isMissing('foo'));267 $this->resolver->setRequired('foo');268 $this->assertTrue($this->resolver->isMissing('foo'));269 }270 public function testIsNotMissingIfSet()271 {272 $this->resolver->setDefault('foo', 'bar');273 $this->assertFalse($this->resolver->isMissing('foo'));274 $this->resolver->setRequired('foo');275 $this->assertFalse($this->resolver->isMissing('foo'));276 }277 public function testIsNotMissingAfterRemove()278 {279 $this->resolver->setRequired('foo');280 $this->resolver->remove('foo');281 $this->assertFalse($this->resolver->isMissing('foo'));282 }283 public function testIsNotMissingAfterClear()284 {285 $this->resolver->setRequired('foo');286 $this->resolver->clear();287 $this->assertFalse($this->resolver->isRequired('foo'));288 }289 public function testGetMissingOptions()290 {291 $this->resolver->setRequired(array('foo', 'bar'));292 $this->resolver->setDefault('bam', 'baz');293 $this->resolver->setDefault('foo', 'boo');294 $this->assertSame(array('bar'), $this->resolver->getMissingOptions());295 }296 ////////////////////////////////////////////////////////////////////////////297 // setDefined()/isDefined()/getDefinedOptions()298 ////////////////////////////////////////////////////////////////////////////299 /**300 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException301 */302 public function testFailIfSetDefinedFromLazyOption()303 {304 $this->resolver->setDefault('foo', function (Options $options) {305 $options->setDefined('bar');306 });307 $this->resolver->resolve();308 }309 public function testDefinedOptionsNotIncludedInResolvedOptions()310 {311 $this->resolver->setDefined('foo');312 $this->assertSame(array(), $this->resolver->resolve());313 }314 public function testDefinedOptionsIncludedIfDefaultSetBefore()315 {316 $this->resolver->setDefault('foo', 'bar');317 $this->resolver->setDefined('foo');318 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());319 }320 public function testDefinedOptionsIncludedIfDefaultSetAfter()321 {322 $this->resolver->setDefined('foo');323 $this->resolver->setDefault('foo', 'bar');324 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());325 }326 public function testDefinedOptionsIncludedIfPassedToResolve()327 {328 $this->resolver->setDefined('foo');329 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve(array('foo' => 'bar')));330 }331 public function testIsDefined()332 {333 $this->assertFalse($this->resolver->isDefined('foo'));334 $this->resolver->setDefined('foo');335 $this->assertTrue($this->resolver->isDefined('foo'));336 }337 public function testLazyOptionsAreDefined()338 {339 $this->assertFalse($this->resolver->isDefined('foo'));340 $this->resolver->setDefault('foo', function (Options $options) {});341 $this->assertTrue($this->resolver->isDefined('foo'));342 }343 public function testRequiredOptionsAreDefined()344 {345 $this->assertFalse($this->resolver->isDefined('foo'));346 $this->resolver->setRequired('foo');347 $this->assertTrue($this->resolver->isDefined('foo'));348 }349 public function testSetOptionsAreDefined()350 {351 $this->assertFalse($this->resolver->isDefined('foo'));352 $this->resolver->setDefault('foo', 'bar');353 $this->assertTrue($this->resolver->isDefined('foo'));354 }355 public function testGetDefinedOptions()356 {357 $this->resolver->setDefined(array('foo', 'bar'));358 $this->resolver->setDefault('baz', 'bam');359 $this->resolver->setRequired('boo');360 $this->assertSame(array('foo', 'bar', 'baz', 'boo'), $this->resolver->getDefinedOptions());361 }362 public function testRemovedOptionsAreNotDefined()363 {364 $this->assertFalse($this->resolver->isDefined('foo'));365 $this->resolver->setDefined('foo');366 $this->assertTrue($this->resolver->isDefined('foo'));367 $this->resolver->remove('foo');368 $this->assertFalse($this->resolver->isDefined('foo'));369 }370 public function testClearedOptionsAreNotDefined()371 {372 $this->assertFalse($this->resolver->isDefined('foo'));373 $this->resolver->setDefined('foo');374 $this->assertTrue($this->resolver->isDefined('foo'));375 $this->resolver->clear();376 $this->assertFalse($this->resolver->isDefined('foo'));377 }378 ////////////////////////////////////////////////////////////////////////////379 // setAllowedTypes()380 ////////////////////////////////////////////////////////////////////////////381 /**382 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException383 */384 public function testSetAllowedTypesFailsIfUnknownOption()385 {386 $this->resolver->setAllowedTypes('foo', 'string');387 }388 /**389 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException390 */391 public function testFailIfSetAllowedTypesFromLazyOption()392 {393 $this->resolver->setDefault('foo', function (Options $options) {394 $options->setAllowedTypes('bar', 'string');395 });396 $this->resolver->setDefault('bar', 'baz');397 $this->resolver->resolve();398 }399 /**400 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException401 * @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[]", but is of type "DateTime[]".402 */403 public function testResolveFailsIfInvalidTypedArray()404 {405 $this->resolver->setDefined('foo');406 $this->resolver->setAllowedTypes('foo', 'int[]');407 $this->resolver->resolve(array('foo' => array(new \DateTime())));408 }409 /**410 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException411 * @expectedExceptionMessage The option "foo" with value "bar" is expected to be of type "int[]", but is of type "string".412 */413 public function testResolveFailsWithNonArray()414 {415 $this->resolver->setDefined('foo');416 $this->resolver->setAllowedTypes('foo', 'int[]');417 $this->resolver->resolve(array('foo' => 'bar'));418 }419 /**420 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException421 * @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[]", but is of type "integer|stdClass|array|DateTime[]".422 */423 public function testResolveFailsIfTypedArrayContainsInvalidTypes()424 {425 $this->resolver->setDefined('foo');426 $this->resolver->setAllowedTypes('foo', 'int[]');427 $values = range(1, 5);428 $values[] = new \stdClass();429 $values[] = array();430 $values[] = new \DateTime();431 $values[] = 123;432 $this->resolver->resolve(array('foo' => $values));433 }434 /**435 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException436 * @expectedExceptionMessage The option "foo" with value array is expected to be of type "int[][]", but is of type "double[][]".437 */438 public function testResolveFailsWithCorrectLevelsButWrongScalar()439 {440 $this->resolver->setDefined('foo');441 $this->resolver->setAllowedTypes('foo', 'int[][]');442 $this->resolver->resolve(443 array(444 'foo' => array(445 array(1.2),446 ),447 )448 );449 }450 /**451 * @dataProvider provideInvalidTypes452 */453 public function testResolveFailsIfInvalidType($actualType, $allowedType, $exceptionMessage)454 {455 $this->resolver->setDefined('option');456 $this->resolver->setAllowedTypes('option', $allowedType);457 if (method_exists($this, 'expectException')) {458 $this->expectException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException');459 $this->expectExceptionMessage($exceptionMessage);460 } else {461 $this->setExpectedException('Symfony\Component\OptionsResolver\Exception\InvalidOptionsException', $exceptionMessage);462 }463 $this->resolver->resolve(array('option' => $actualType));464 }465 public function provideInvalidTypes()466 {467 return array(468 array(true, 'string', 'The option "option" with value true is expected to be of type "string", but is of type "boolean".'),469 array(false, 'string', 'The option "option" with value false is expected to be of type "string", but is of type "boolean".'),470 array(fopen(__FILE__, 'r'), 'string', 'The option "option" with value resource is expected to be of type "string", but is of type "resource".'),471 array(array(), 'string', 'The option "option" with value array is expected to be of type "string", but is of type "array".'),472 array(new OptionsResolver(), 'string', 'The option "option" with value Symfony\Component\OptionsResolver\OptionsResolver is expected to be of type "string", but is of type "Symfony\Component\OptionsResolver\OptionsResolver".'),473 array(42, 'string', 'The option "option" with value 42 is expected to be of type "string", but is of type "integer".'),474 array(null, 'string', 'The option "option" with value null is expected to be of type "string", but is of type "NULL".'),475 array('bar', '\stdClass', 'The option "option" with value "bar" is expected to be of type "\stdClass", but is of type "string".'),476 );477 }478 public function testResolveSucceedsIfValidType()479 {480 $this->resolver->setDefault('foo', 'bar');481 $this->resolver->setAllowedTypes('foo', 'string');482 $this->assertNotEmpty($this->resolver->resolve());483 }484 /**485 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException486 * @expectedExceptionMessage The option "foo" with value 42 is expected to be of type "string" or "bool", but is of type "integer".487 */488 public function testResolveFailsIfInvalidTypeMultiple()489 {490 $this->resolver->setDefault('foo', 42);491 $this->resolver->setAllowedTypes('foo', array('string', 'bool'));492 $this->resolver->resolve();493 }494 public function testResolveSucceedsIfValidTypeMultiple()495 {496 $this->resolver->setDefault('foo', true);497 $this->resolver->setAllowedTypes('foo', array('string', 'bool'));498 $this->assertNotEmpty($this->resolver->resolve());499 }500 public function testResolveSucceedsIfInstanceOfClass()501 {502 $this->resolver->setDefault('foo', new \stdClass());503 $this->resolver->setAllowedTypes('foo', '\stdClass');504 $this->assertNotEmpty($this->resolver->resolve());505 }506 public function testResolveSucceedsIfTypedArray()507 {508 $this->resolver->setDefault('foo', null);509 $this->resolver->setAllowedTypes('foo', array('null', 'DateTime[]'));510 $data = array(511 'foo' => array(512 new \DateTime(),513 new \DateTime(),514 ),515 );516 $result = $this->resolver->resolve($data);517 $this->assertEquals($data, $result);518 }519 /**520 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException521 */522 public function testResolveFailsIfNotInstanceOfClass()523 {524 $this->resolver->setDefault('foo', 'bar');525 $this->resolver->setAllowedTypes('foo', '\stdClass');526 $this->resolver->resolve();527 }528 ////////////////////////////////////////////////////////////////////////////529 // addAllowedTypes()530 ////////////////////////////////////////////////////////////////////////////531 /**532 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException533 */534 public function testAddAllowedTypesFailsIfUnknownOption()535 {536 $this->resolver->addAllowedTypes('foo', 'string');537 }538 /**539 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException540 */541 public function testFailIfAddAllowedTypesFromLazyOption()542 {543 $this->resolver->setDefault('foo', function (Options $options) {544 $options->addAllowedTypes('bar', 'string');545 });546 $this->resolver->setDefault('bar', 'baz');547 $this->resolver->resolve();548 }549 /**550 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException551 */552 public function testResolveFailsIfInvalidAddedType()553 {554 $this->resolver->setDefault('foo', 42);555 $this->resolver->addAllowedTypes('foo', 'string');556 $this->resolver->resolve();557 }558 public function testResolveSucceedsIfValidAddedType()559 {560 $this->resolver->setDefault('foo', 'bar');561 $this->resolver->addAllowedTypes('foo', 'string');562 $this->assertNotEmpty($this->resolver->resolve());563 }564 /**565 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException566 */567 public function testResolveFailsIfInvalidAddedTypeMultiple()568 {569 $this->resolver->setDefault('foo', 42);570 $this->resolver->addAllowedTypes('foo', array('string', 'bool'));571 $this->resolver->resolve();572 }573 public function testResolveSucceedsIfValidAddedTypeMultiple()574 {575 $this->resolver->setDefault('foo', 'bar');576 $this->resolver->addAllowedTypes('foo', array('string', 'bool'));577 $this->assertNotEmpty($this->resolver->resolve());578 }579 public function testAddAllowedTypesDoesNotOverwrite()580 {581 $this->resolver->setDefault('foo', 'bar');582 $this->resolver->setAllowedTypes('foo', 'string');583 $this->resolver->addAllowedTypes('foo', 'bool');584 $this->resolver->setDefault('foo', 'bar');585 $this->assertNotEmpty($this->resolver->resolve());586 }587 public function testAddAllowedTypesDoesNotOverwrite2()588 {589 $this->resolver->setDefault('foo', 'bar');590 $this->resolver->setAllowedTypes('foo', 'string');591 $this->resolver->addAllowedTypes('foo', 'bool');592 $this->resolver->setDefault('foo', false);593 $this->assertNotEmpty($this->resolver->resolve());594 }595 ////////////////////////////////////////////////////////////////////////////596 // setAllowedValues()597 ////////////////////////////////////////////////////////////////////////////598 /**599 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException600 */601 public function testSetAllowedValuesFailsIfUnknownOption()602 {603 $this->resolver->setAllowedValues('foo', 'bar');604 }605 /**606 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException607 */608 public function testFailIfSetAllowedValuesFromLazyOption()609 {610 $this->resolver->setDefault('foo', function (Options $options) {611 $options->setAllowedValues('bar', 'baz');612 });613 $this->resolver->setDefault('bar', 'baz');614 $this->resolver->resolve();615 }616 /**617 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException618 * @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar".619 */620 public function testResolveFailsIfInvalidValue()621 {622 $this->resolver->setDefined('foo');623 $this->resolver->setAllowedValues('foo', 'bar');624 $this->resolver->resolve(array('foo' => 42));625 }626 /**627 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException628 * @expectedExceptionMessage The option "foo" with value null is invalid. Accepted values are: "bar".629 */630 public function testResolveFailsIfInvalidValueIsNull()631 {632 $this->resolver->setDefault('foo', null);633 $this->resolver->setAllowedValues('foo', 'bar');634 $this->resolver->resolve();635 }636 /**637 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException638 */639 public function testResolveFailsIfInvalidValueStrict()640 {641 $this->resolver->setDefault('foo', 42);642 $this->resolver->setAllowedValues('foo', '42');643 $this->resolver->resolve();644 }645 public function testResolveSucceedsIfValidValue()646 {647 $this->resolver->setDefault('foo', 'bar');648 $this->resolver->setAllowedValues('foo', 'bar');649 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());650 }651 public function testResolveSucceedsIfValidValueIsNull()652 {653 $this->resolver->setDefault('foo', null);654 $this->resolver->setAllowedValues('foo', null);655 $this->assertEquals(array('foo' => null), $this->resolver->resolve());656 }657 /**658 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException659 * @expectedExceptionMessage The option "foo" with value 42 is invalid. Accepted values are: "bar", false, null.660 */661 public function testResolveFailsIfInvalidValueMultiple()662 {663 $this->resolver->setDefault('foo', 42);664 $this->resolver->setAllowedValues('foo', array('bar', false, null));665 $this->resolver->resolve();666 }667 public function testResolveSucceedsIfValidValueMultiple()668 {669 $this->resolver->setDefault('foo', 'baz');670 $this->resolver->setAllowedValues('foo', array('bar', 'baz'));671 $this->assertEquals(array('foo' => 'baz'), $this->resolver->resolve());672 }673 public function testResolveFailsIfClosureReturnsFalse()674 {675 $this->resolver->setDefault('foo', 42);676 $this->resolver->setAllowedValues('foo', function ($value) use (&$passedValue) {677 $passedValue = $value;678 return false;679 });680 try {681 $this->resolver->resolve();682 $this->fail('Should fail');683 } catch (InvalidOptionsException $e) {684 }685 $this->assertSame(42, $passedValue);686 }687 public function testResolveSucceedsIfClosureReturnsTrue()688 {689 $this->resolver->setDefault('foo', 'bar');690 $this->resolver->setAllowedValues('foo', function ($value) use (&$passedValue) {691 $passedValue = $value;692 return true;693 });694 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());695 $this->assertSame('bar', $passedValue);696 }697 /**698 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException699 */700 public function testResolveFailsIfAllClosuresReturnFalse()701 {702 $this->resolver->setDefault('foo', 42);703 $this->resolver->setAllowedValues('foo', array(704 function () { return false; },705 function () { return false; },706 function () { return false; },707 ));708 $this->resolver->resolve();709 }710 public function testResolveSucceedsIfAnyClosureReturnsTrue()711 {712 $this->resolver->setDefault('foo', 'bar');713 $this->resolver->setAllowedValues('foo', array(714 function () { return false; },715 function () { return true; },716 function () { return false; },717 ));718 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());719 }720 ////////////////////////////////////////////////////////////////////////////721 // addAllowedValues()722 ////////////////////////////////////////////////////////////////////////////723 /**724 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException725 */726 public function testAddAllowedValuesFailsIfUnknownOption()727 {728 $this->resolver->addAllowedValues('foo', 'bar');729 }730 /**731 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException732 */733 public function testFailIfAddAllowedValuesFromLazyOption()734 {735 $this->resolver->setDefault('foo', function (Options $options) {736 $options->addAllowedValues('bar', 'baz');737 });738 $this->resolver->setDefault('bar', 'baz');739 $this->resolver->resolve();740 }741 /**742 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException743 */744 public function testResolveFailsIfInvalidAddedValue()745 {746 $this->resolver->setDefault('foo', 42);747 $this->resolver->addAllowedValues('foo', 'bar');748 $this->resolver->resolve();749 }750 public function testResolveSucceedsIfValidAddedValue()751 {752 $this->resolver->setDefault('foo', 'bar');753 $this->resolver->addAllowedValues('foo', 'bar');754 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());755 }756 public function testResolveSucceedsIfValidAddedValueIsNull()757 {758 $this->resolver->setDefault('foo', null);759 $this->resolver->addAllowedValues('foo', null);760 $this->assertEquals(array('foo' => null), $this->resolver->resolve());761 }762 /**763 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException764 */765 public function testResolveFailsIfInvalidAddedValueMultiple()766 {767 $this->resolver->setDefault('foo', 42);768 $this->resolver->addAllowedValues('foo', array('bar', 'baz'));769 $this->resolver->resolve();770 }771 public function testResolveSucceedsIfValidAddedValueMultiple()772 {773 $this->resolver->setDefault('foo', 'bar');774 $this->resolver->addAllowedValues('foo', array('bar', 'baz'));775 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());776 }777 public function testAddAllowedValuesDoesNotOverwrite()778 {779 $this->resolver->setDefault('foo', 'bar');780 $this->resolver->setAllowedValues('foo', 'bar');781 $this->resolver->addAllowedValues('foo', 'baz');782 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());783 }784 public function testAddAllowedValuesDoesNotOverwrite2()785 {786 $this->resolver->setDefault('foo', 'baz');787 $this->resolver->setAllowedValues('foo', 'bar');788 $this->resolver->addAllowedValues('foo', 'baz');789 $this->assertEquals(array('foo' => 'baz'), $this->resolver->resolve());790 }791 /**792 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException793 */794 public function testResolveFailsIfAllAddedClosuresReturnFalse()795 {796 $this->resolver->setDefault('foo', 42);797 $this->resolver->setAllowedValues('foo', function () { return false; });798 $this->resolver->addAllowedValues('foo', function () { return false; });799 $this->resolver->resolve();800 }801 public function testResolveSucceedsIfAnyAddedClosureReturnsTrue()802 {803 $this->resolver->setDefault('foo', 'bar');804 $this->resolver->setAllowedValues('foo', function () { return false; });805 $this->resolver->addAllowedValues('foo', function () { return true; });806 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());807 }808 public function testResolveSucceedsIfAnyAddedClosureReturnsTrue2()809 {810 $this->resolver->setDefault('foo', 'bar');811 $this->resolver->setAllowedValues('foo', function () { return true; });812 $this->resolver->addAllowedValues('foo', function () { return false; });813 $this->assertEquals(array('foo' => 'bar'), $this->resolver->resolve());814 }815 ////////////////////////////////////////////////////////////////////////////816 // setNormalizer()817 ////////////////////////////////////////////////////////////////////////////818 public function testSetNormalizerReturnsThis()819 {820 $this->resolver->setDefault('foo', 'bar');821 $this->assertSame($this->resolver, $this->resolver->setNormalizer('foo', function () {}));822 }823 public function testSetNormalizerClosure()824 {825 $this->resolver->setDefault('foo', 'bar');826 $this->resolver->setNormalizer('foo', function () {827 return 'normalized';828 });829 $this->assertEquals(array('foo' => 'normalized'), $this->resolver->resolve());830 }831 /**832 * @expectedException \Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException833 */834 public function testSetNormalizerFailsIfUnknownOption()835 {836 $this->resolver->setNormalizer('foo', function () {});837 }838 /**839 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException840 */841 public function testFailIfSetNormalizerFromLazyOption()842 {843 $this->resolver->setDefault('foo', function (Options $options) {844 $options->setNormalizer('foo', function () {});845 });846 $this->resolver->setDefault('bar', 'baz');847 $this->resolver->resolve();848 }849 public function testNormalizerReceivesSetOption()850 {851 $this->resolver->setDefault('foo', 'bar');852 $this->resolver->setNormalizer('foo', function (Options $options, $value) {853 return 'normalized['.$value.']';854 });855 $this->assertEquals(array('foo' => 'normalized[bar]'), $this->resolver->resolve());856 }857 public function testNormalizerReceivesPassedOption()858 {859 $this->resolver->setDefault('foo', 'bar');860 $this->resolver->setNormalizer('foo', function (Options $options, $value) {861 return 'normalized['.$value.']';862 });863 $resolved = $this->resolver->resolve(array('foo' => 'baz'));864 $this->assertEquals(array('foo' => 'normalized[baz]'), $resolved);865 }866 /**867 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException868 */869 public function testValidateTypeBeforeNormalization()870 {871 $this->resolver->setDefault('foo', 'bar');872 $this->resolver->setAllowedTypes('foo', 'int');873 $this->resolver->setNormalizer('foo', function () {874 Assert::fail('Should not be called.');875 });876 $this->resolver->resolve();877 }878 /**879 * @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException880 */881 public function testValidateValueBeforeNormalization()882 {883 $this->resolver->setDefault('foo', 'bar');884 $this->resolver->setAllowedValues('foo', 'baz');885 $this->resolver->setNormalizer('foo', function () {886 Assert::fail('Should not be called.');887 });888 $this->resolver->resolve();889 }890 public function testNormalizerCanAccessOtherOptions()891 {892 $this->resolver->setDefault('default', 'bar');893 $this->resolver->setDefault('norm', 'baz');894 $this->resolver->setNormalizer('norm', function (Options $options) {895 /* @var TestCase $test */896 Assert::assertSame('bar', $options['default']);897 return 'normalized';898 });899 $this->assertEquals(array(900 'default' => 'bar',901 'norm' => 'normalized',902 ), $this->resolver->resolve());903 }904 public function testNormalizerCanAccessLazyOptions()905 {906 $this->resolver->setDefault('lazy', function (Options $options) {907 return 'bar';908 });909 $this->resolver->setDefault('norm', 'baz');910 $this->resolver->setNormalizer('norm', function (Options $options) {911 /* @var TestCase $test */912 Assert::assertEquals('bar', $options['lazy']);913 return 'normalized';914 });915 $this->assertEquals(array(916 'lazy' => 'bar',917 'norm' => 'normalized',918 ), $this->resolver->resolve());919 }920 /**921 * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException922 */923 public function testFailIfCyclicDependencyBetweenNormalizers()924 {925 $this->resolver->setDefault('norm1', 'bar');926 $this->resolver->setDefault('norm2', 'baz');927 $this->resolver->setNormalizer('norm1', function (Options $options) {928 $options['norm2'];929 });930 $this->resolver->setNormalizer('norm2', function (Options $options) {931 $options['norm1'];932 });933 $this->resolver->resolve();934 }935 /**936 * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException937 */938 public function testFailIfCyclicDependencyBetweenNormalizerAndLazyOption()939 {940 $this->resolver->setDefault('lazy', function (Options $options) {941 $options['norm'];942 });943 $this->resolver->setDefault('norm', 'baz');944 $this->resolver->setNormalizer('norm', function (Options $options) {945 $options['lazy'];946 });947 $this->resolver->resolve();948 }949 public function testCaughtExceptionFromNormalizerDoesNotCrashOptionResolver()950 {951 $throw = true;952 $this->resolver->setDefaults(array('catcher' => null, 'thrower' => null));953 $this->resolver->setNormalizer('catcher', function (Options $options) {954 try {955 return $options['thrower'];956 } catch (\Exception $e) {957 return false;958 }959 });960 $this->resolver->setNormalizer('thrower', function () use (&$throw) {961 if ($throw) {962 $throw = false;963 throw new \UnexpectedValueException('throwing');964 }965 return true;966 });967 $this->assertSame(array('catcher' => false, 'thrower' => true), $this->resolver->resolve());968 }969 public function testCaughtExceptionFromLazyDoesNotCrashOptionResolver()970 {971 $throw = true;972 $this->resolver->setDefault('catcher', function (Options $options) {973 try {974 return $options['thrower'];975 } catch (\Exception $e) {976 return false;977 }978 });979 $this->resolver->setDefault('thrower', function (Options $options) use (&$throw) {980 if ($throw) {981 $throw = false;982 throw new \UnexpectedValueException('throwing');983 }984 return true;985 });986 $this->assertSame(array('catcher' => false, 'thrower' => true), $this->resolver->resolve());987 }988 public function testInvokeEachNormalizerOnlyOnce()989 {990 $calls = 0;991 $this->resolver->setDefault('norm1', 'bar');992 $this->resolver->setDefault('norm2', 'baz');993 $this->resolver->setNormalizer('norm1', function ($options) use (&$calls) {994 Assert::assertSame(1, ++$calls);995 $options['norm2'];996 });997 $this->resolver->setNormalizer('norm2', function () use (&$calls) {998 Assert::assertSame(2, ++$calls);999 });1000 $this->resolver->resolve();1001 $this->assertSame(2, $calls);1002 }1003 public function testNormalizerNotCalledForUnsetOptions()1004 {1005 $this->resolver->setDefined('norm');1006 $this->resolver->setNormalizer('norm', function () {1007 Assert::fail('Should not be called.');1008 });1009 $this->assertEmpty($this->resolver->resolve());1010 }1011 ////////////////////////////////////////////////////////////////////////////1012 // setDefaults()1013 ////////////////////////////////////////////////////////////////////////////1014 public function testSetDefaultsReturnsThis()1015 {1016 $this->assertSame($this->resolver, $this->resolver->setDefaults(array('foo', 'bar')));1017 }1018 public function testSetDefaults()1019 {1020 $this->resolver->setDefault('one', '1');1021 $this->resolver->setDefault('two', 'bar');1022 $this->resolver->setDefaults(array(1023 'two' => '2',1024 'three' => '3',1025 ));1026 $this->assertEquals(array(1027 'one' => '1',1028 'two' => '2',1029 'three' => '3',1030 ), $this->resolver->resolve());1031 }1032 /**1033 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1034 */1035 public function testFailIfSetDefaultsFromLazyOption()1036 {1037 $this->resolver->setDefault('foo', function (Options $options) {1038 $options->setDefaults(array('two' => '2'));1039 });1040 $this->resolver->resolve();1041 }1042 ////////////////////////////////////////////////////////////////////////////1043 // remove()1044 ////////////////////////////////////////////////////////////////////////////1045 public function testRemoveReturnsThis()1046 {1047 $this->resolver->setDefault('foo', 'bar');1048 $this->assertSame($this->resolver, $this->resolver->remove('foo'));1049 }1050 public function testRemoveSingleOption()1051 {1052 $this->resolver->setDefault('foo', 'bar');1053 $this->resolver->setDefault('baz', 'boo');1054 $this->resolver->remove('foo');1055 $this->assertSame(array('baz' => 'boo'), $this->resolver->resolve());1056 }1057 public function testRemoveMultipleOptions()1058 {1059 $this->resolver->setDefault('foo', 'bar');1060 $this->resolver->setDefault('baz', 'boo');1061 $this->resolver->setDefault('doo', 'dam');1062 $this->resolver->remove(array('foo', 'doo'));1063 $this->assertSame(array('baz' => 'boo'), $this->resolver->resolve());1064 }1065 public function testRemoveLazyOption()1066 {1067 $this->resolver->setDefault('foo', function (Options $options) {1068 return 'lazy';1069 });1070 $this->resolver->remove('foo');1071 $this->assertSame(array(), $this->resolver->resolve());1072 }1073 public function testRemoveNormalizer()1074 {1075 $this->resolver->setDefault('foo', 'bar');1076 $this->resolver->setNormalizer('foo', function (Options $options, $value) {1077 return 'normalized';1078 });1079 $this->resolver->remove('foo');1080 $this->resolver->setDefault('foo', 'bar');1081 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1082 }1083 public function testRemoveAllowedTypes()1084 {1085 $this->resolver->setDefault('foo', 'bar');1086 $this->resolver->setAllowedTypes('foo', 'int');1087 $this->resolver->remove('foo');1088 $this->resolver->setDefault('foo', 'bar');1089 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1090 }1091 public function testRemoveAllowedValues()1092 {1093 $this->resolver->setDefault('foo', 'bar');1094 $this->resolver->setAllowedValues('foo', array('baz', 'boo'));1095 $this->resolver->remove('foo');1096 $this->resolver->setDefault('foo', 'bar');1097 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1098 }1099 /**1100 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1101 */1102 public function testFailIfRemoveFromLazyOption()1103 {1104 $this->resolver->setDefault('foo', function (Options $options) {1105 $options->remove('bar');1106 });1107 $this->resolver->setDefault('bar', 'baz');1108 $this->resolver->resolve();1109 }1110 public function testRemoveUnknownOptionIgnored()1111 {1112 $this->assertNotNull($this->resolver->remove('foo'));1113 }1114 ////////////////////////////////////////////////////////////////////////////1115 // clear()1116 ////////////////////////////////////////////////////////////////////////////1117 public function testClearReturnsThis()1118 {1119 $this->assertSame($this->resolver, $this->resolver->clear());1120 }1121 public function testClearRemovesAllOptions()1122 {1123 $this->resolver->setDefault('one', 1);1124 $this->resolver->setDefault('two', 2);1125 $this->resolver->clear();1126 $this->assertEmpty($this->resolver->resolve());1127 }1128 public function testClearLazyOption()1129 {1130 $this->resolver->setDefault('foo', function (Options $options) {1131 return 'lazy';1132 });1133 $this->resolver->clear();1134 $this->assertSame(array(), $this->resolver->resolve());1135 }1136 public function testClearNormalizer()1137 {1138 $this->resolver->setDefault('foo', 'bar');1139 $this->resolver->setNormalizer('foo', function (Options $options, $value) {1140 return 'normalized';1141 });1142 $this->resolver->clear();1143 $this->resolver->setDefault('foo', 'bar');1144 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1145 }1146 public function testClearAllowedTypes()1147 {1148 $this->resolver->setDefault('foo', 'bar');1149 $this->resolver->setAllowedTypes('foo', 'int');1150 $this->resolver->clear();1151 $this->resolver->setDefault('foo', 'bar');1152 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1153 }1154 public function testClearAllowedValues()1155 {1156 $this->resolver->setDefault('foo', 'bar');1157 $this->resolver->setAllowedValues('foo', 'baz');1158 $this->resolver->clear();1159 $this->resolver->setDefault('foo', 'bar');1160 $this->assertSame(array('foo' => 'bar'), $this->resolver->resolve());1161 }1162 /**1163 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1164 */1165 public function testFailIfClearFromLazyption()1166 {1167 $this->resolver->setDefault('foo', function (Options $options) {1168 $options->clear();1169 });1170 $this->resolver->setDefault('bar', 'baz');1171 $this->resolver->resolve();1172 }1173 public function testClearOptionAndNormalizer()1174 {1175 $this->resolver->setDefault('foo1', 'bar');1176 $this->resolver->setNormalizer('foo1', function (Options $options) {1177 return '';1178 });1179 $this->resolver->setDefault('foo2', 'bar');1180 $this->resolver->setNormalizer('foo2', function (Options $options) {1181 return '';1182 });1183 $this->resolver->clear();1184 $this->assertEmpty($this->resolver->resolve());1185 }1186 ////////////////////////////////////////////////////////////////////////////1187 // ArrayAccess1188 ////////////////////////////////////////////////////////////////////////////1189 public function testArrayAccess()1190 {1191 $this->resolver->setDefault('default1', 0);1192 $this->resolver->setDefault('default2', 1);1193 $this->resolver->setRequired('required');1194 $this->resolver->setDefined('defined');1195 $this->resolver->setDefault('lazy1', function (Options $options) {1196 return 'lazy';1197 });1198 $this->resolver->setDefault('lazy2', function (Options $options) {1199 Assert::assertTrue(isset($options['default1']));1200 Assert::assertTrue(isset($options['default2']));1201 Assert::assertTrue(isset($options['required']));1202 Assert::assertTrue(isset($options['lazy1']));1203 Assert::assertTrue(isset($options['lazy2']));1204 Assert::assertFalse(isset($options['defined']));1205 Assert::assertSame(0, $options['default1']);1206 Assert::assertSame(42, $options['default2']);1207 Assert::assertSame('value', $options['required']);1208 Assert::assertSame('lazy', $options['lazy1']);1209 // Obviously $options['lazy'] and $options['defined'] cannot be1210 // accessed1211 });1212 $this->resolver->resolve(array('default2' => 42, 'required' => 'value'));1213 }1214 /**1215 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1216 */1217 public function testArrayAccessGetFailsOutsideResolve()1218 {1219 $this->resolver->setDefault('default', 0);1220 $this->resolver['default'];1221 }1222 /**1223 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1224 */1225 public function testArrayAccessExistsFailsOutsideResolve()1226 {1227 $this->resolver->setDefault('default', 0);1228 isset($this->resolver['default']);1229 }1230 /**1231 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1232 */1233 public function testArrayAccessSetNotSupported()1234 {1235 $this->resolver['default'] = 0;1236 }1237 /**1238 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1239 */1240 public function testArrayAccessUnsetNotSupported()1241 {1242 $this->resolver->setDefault('default', 0);1243 unset($this->resolver['default']);1244 }1245 /**1246 * @expectedException \Symfony\Component\OptionsResolver\Exception\NoSuchOptionException1247 * @expectedExceptionMessage The option "undefined" does not exist. Defined options are: "foo", "lazy".1248 */1249 public function testFailIfGetNonExisting()1250 {1251 $this->resolver->setDefault('foo', 'bar');1252 $this->resolver->setDefault('lazy', function (Options $options) {1253 $options['undefined'];1254 });1255 $this->resolver->resolve();1256 }1257 /**1258 * @expectedException \Symfony\Component\OptionsResolver\Exception\NoSuchOptionException1259 * @expectedExceptionMessage The optional option "defined" has no value set. You should make sure it is set with "isset" before reading it.1260 */1261 public function testFailIfGetDefinedButUnset()1262 {1263 $this->resolver->setDefined('defined');1264 $this->resolver->setDefault('lazy', function (Options $options) {1265 $options['defined'];1266 });1267 $this->resolver->resolve();1268 }1269 /**1270 * @expectedException \Symfony\Component\OptionsResolver\Exception\OptionDefinitionException1271 */1272 public function testFailIfCyclicDependency()1273 {1274 $this->resolver->setDefault('lazy1', function (Options $options) {1275 $options['lazy2'];1276 });1277 $this->resolver->setDefault('lazy2', function (Options $options) {1278 $options['lazy1'];1279 });1280 $this->resolver->resolve();1281 }1282 ////////////////////////////////////////////////////////////////////////////1283 // Countable1284 ////////////////////////////////////////////////////////////////////////////1285 public function testCount()1286 {1287 $this->resolver->setDefault('default', 0);1288 $this->resolver->setRequired('required');1289 $this->resolver->setDefined('defined');1290 $this->resolver->setDefault('lazy1', function () {});1291 $this->resolver->setDefault('lazy2', function (Options $options) {1292 Assert::assertCount(4, $options);1293 });1294 $this->assertCount(4, $this->resolver->resolve(array('required' => 'value')));1295 }1296 /**1297 * In resolve() we count the options that are actually set (which may be1298 * only a subset of the defined options). Outside of resolve(), it's not1299 * clear what is counted.1300 *1301 * @expectedException \Symfony\Component\OptionsResolver\Exception\AccessException1302 */1303 public function testCountFailsOutsideResolve()1304 {1305 $this->resolver->setDefault('foo', 0);1306 $this->resolver->setRequired('bar');1307 $this->resolver->setDefined('bar');1308 $this->resolver->setDefault('lazy1', function () {});1309 count($this->resolver);1310 }1311}...

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1use mageekguy\atoum\autoloader;2$autoloader = new autoloader();3$autoloader->addNamespace('mageekguy\atoum\tests\units', '/path/to/your/tests/units');4$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters', '/path/to/your/tests/units/asserters');5$autoloader->addNamespace('mageekguy\atoum\tests\units\mocks', '/path/to/your/tests/units/mocks');6$autoloader->addNamespace('mageekguy\atoum\tests\units\reports', '/path/to/your/tests/units/reports');7$autoloader->addNamespace('mageekguy\atoum\tests\units\writers', '/path/to/your/tests/units/writers');8$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters\adapter', '/path/to/your/tests/units/asserters/adapter');9$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters\php', '/path/to/your/tests/units/asserters/php');10$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters\php\string', '/path/to/your/tests/units/asserters/php/string');11$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters\php\object', '/path/to/your/tests/units/asserters/php/object');12$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters\php\object\property', '/path/to/your/tests/units/asserters/php/object/property');13$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters\php\object\property', '/path/to/your/tests/units/asserters/php/object/property');14$autoloader->addNamespace('mageekguy\atoum\tests\units\asserters\php\object\property', '/path/to/your/tests/units/asserters/php/object/property');15$autoloader->addNamespace('mageekguy

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1require_once __DIR__ . '/vendor/autoload.php';2require_once __DIR__ . '/vendor/atoum/atoum/classes/autoloader.php';3\mageekguy\atoum\autoloader::get()4 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes')5 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/mock')6 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/mock/adapter')7 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/mock/asserters')8 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/asserter')9 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/exceptions')10 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/test')11 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/tools')12 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/runner')13 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/report')14 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/asserters')15 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/asserters/adapter')16 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/asserters/php')17 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/asserters/variable')18 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/adapter')19 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/adapter/invoker')20 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/adapter/invoker/mageekguy')21 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/adapter/invoker/mageekguy/atoum')22 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/adapter/invoker/mageekguy/atoum/adapter')23 ->addDirectory(__DIR__ . '/vendor/atoum/atoum/classes/adapter/invoker/mageekguy/atoum/adapter/

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1$autoloader = new \atoum\autoloader();2$autoloader->addNamespace('atoum\atoum\tests\units', __DIR__ . '/tests/units');3$autoloader->addNamespace('atoum\atoum', __DIR__ . '/classes');4$autoloader->register();5$autoloader = new \atoum\autoloader();6$autoloader->addNamespace('atoum\atoum\tests\units', __DIR__ . '/tests/units');7$autoloader->addNamespace('atoum\atoum', __DIR__ . '/classes');8$autoloader->register();9$autoloader = new \atoum\autoloader();10$autoloader->addNamespace('atoum\atoum\tests\units', __DIR__ . '/tests/units');11$autoloader->addNamespace('atoum\atoum', __DIR__ . '/classes');12$autoloader->register();13$autoloader = new \atoum\autoloader();14$autoloader->addNamespace('atoum\atoum\tests\units', __DIR__ . '/tests/units');15$autoloader->addNamespace('atoum\atoum', __DIR__ . '/classes');16$autoloader->register();17$autoloader = new \atoum\autoloader();18$autoloader->addNamespace('atoum\atoum\tests\units', __DIR__ . '/tests/units');19$autoloader->addNamespace('atoum\atoum', __DIR__ . '/classes');20$autoloader->register();21$autoloader = new \atoum\autoloader();22$autoloader->addNamespace('atoum\atoum\tests\units', __DIR__ . '/tests/units');23$autoloader->addNamespace('atoum\atoum', __DIR__ . '/classes');24$autoloader->register();

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1$autoloader = new \mageekguy\atoum\autoloader();2$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\mock', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/mock');3$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\mock\streams', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/mock/streams');4$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\mock\php', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/mock/php');5$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\asserters', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/asserters');6$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\stubs', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/stubs');7$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\report\fields\runner\tests\coverage', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/report/fields/runner/tests/coverage');8$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\report\fields\runner\tests\coverage\html', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/report/fields/runner/tests/coverage/html');9$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\report\fields\runner\tests\coverage\clover', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/report/fields/runner/tests/coverage/clover');10$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\report\fields\runner\tests\coverage\php', __DIR__.'/../../vendor/atoum/atoum/classes/tests/units/report/fields/runner/tests/coverage/php');11$autoloader->addNamespaceAlias('mageekguy\atoum\tests\units\report\fields\runner

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');2$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');3$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');4$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');5$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');6$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');7$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');8$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');9$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');10$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');11$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');12$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');13$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');14$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');15$test->setBootstrapFile(__DIR__ . '/../../vendor/autoload.php');

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1require_once __DIR__ . '/vendor/autoload.php';2use mageekguy\atoum;3$script->addDefaultReport();4$runner->addTestsFromDirectory(__DIR__ . '/tests/units');5$runner->setBootstrapFile(__DIR__ . '/tests/bootstrap.php');6$runner->addTestsFromDirectory(__DIR__ . '/tests/units');7$runner->addExtension(new atoum\report\fields\runner\result\logo());8$runner->addExtension(new atoum\report\fields\runner\atoum\version());9$runner->addExtension(new atoum\report\fields\runner\result\duration());10$runner->addExtension(new atoum\report\fields\runner\result\memory());11$runner->addExtension(new atoum\report\fields\runner\result\readme());12$runner->addExtension(new atoum\report\fields\test\run\duration());13$runner->addExtension(new atoum\report\fields\test\run\memory());14$runner->addExtension(new atoum\report\fields\test\event\fail());15$runner->addExtension(new atoum\report\fields\test\event\error());16$runner->addExtension(new atoum\report\fields\test\event\exception());17$runner->addExtension(new atoum\report\fields\test\event\void());18$runner->addExtension(new atoum\report\fields\test\event\uncompleted());19$runner->addExtension(new atoum\report\fields\test\event\skipped());20$runner->addExtension(new atoum\report\fields\test\event\output());21$runner->addExtension(new atoum\report\fields\test\event\fail\diff());22$runner->addExtension(new atoum\report\fields\test\event\error\diff());23$runner->addExtension(new atoum\report\fields\test\event\exception\diff());24$runner->addExtension(new atoum\report\fields\test\event\void\diff());25$runner->addExtension(new atoum\report\fields\test\event\uncompleted\diff());26$runner->addExtension(new atoum\report\fields\test\event\skipped\diff());

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1$autoloader = require_once __DIR__ . '/vendor/autoload.php';2$autoloader->addDirectory(__DIR__ . '/src');3namespace Atoum;4{5 public function __construct()6 {7 echo 'I am the resolver';8 }9}10$autoloader = require_once __DIR__ . '/vendor/autoload.php';11$autoloader->addDirectory(__DIR__ . '/src');12new Atoum\Resolver();

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1$autoloader->addNamespace('Atoum\Atoum', array(__DIR__ . '/atoum/lib'));2$autoloader->addNamespace('Atoum\Atoum\Reports', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports'));3$autoloader->addNamespace('Atoum\Atoum\Reports\Templates', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports/Templates'));4$autoloader->addNamespace('Atoum\Atoum\Reports\Templates\Html', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports/Templates/Html'));5$autoloader->addNamespace('Atoum\Atoum\Reports\Templates\Html\Dashboard', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports/Templates/Html/Dashboard'));6$autoloader->addNamespace('Atoum\Atoum\Reports\Templates\Html\Dashboard\Widgets', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports/Templates/Html/Dashboard/Widgets'));7$autoloader->addNamespace('Atoum\Atoum\Reports\Templates\Html\Dashboard\Widgets\History', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports/Templates/Html/Dashboard/Widgets/History'));8$autoloader->addNamespace('Atoum\Atoum\Reports\Templates\Html\Dashboard\Widgets\History\Charts', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports/Templates/Html/Dashboard/Widgets/History/Charts'));9$autoloader->addNamespace('Atoum\Atoum\Reports\Templates\Html\Dashboard\Widgets\History\Charts\Highcharts', array(__DIR__ . '/atoum/lib/Atoum/Atoum/Reports/Templates/Html/Dashboard/Widgets/History/Charts/Highcharts'));10$autoloader->addNamespace('Atoum\Atoum\Reports\Templates\Html\Dashboard\Widgets\History\Charts\Highcharts\Options', array(__DIR__ . '/atoum/lib/Atoum/Atou

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1require_once 'vendor/autoload.php';2use Atoum\Atoum\Resolver;3$atoum = new Resolver();4$atoum->resolve('atoum');5require_once 'vendor/autoload.php';6use Atoum\Atoum\Resolver;7$atoum = new Resolver();8$atoum->resolve('PHPUnit');9require_once 'vendor/autoload.php';10use Atoum\Atoum\Resolver;11$atoum = new Resolver();12$atoum->resolve('PHPunit');

Full Screen

Full Screen

resolver

Using AI Code Generation

copy

Full Screen

1$atoum = new \mageekguy\atoum\script\resolver();2$atoum->setArguments(array('--test-it', 'tests/units/'));3$atoum->run();4$atoum = new \mageekguy\atoum\script\resolver();5$atoum->setArguments(array('--test-it', 'tests/units/'));6$atoum->run();7$atoum = new \mageekguy\atoum\script\resolver();8$atoum->setArguments(array('--test-it', 'tests/units/'));9$atoum->run();10Fatal error: Uncaught exception 'mageekguy\atoum\exceptions\logic\invalidArgument' with message 'Argument of mageekguy\atoum\script\resolver::setArguments() must be an array' in /home/travis/build/maurobonfietti/symfony2-project/vendor/atoum/atoum/classes/script/resolver.php:5411$atoum = new \mageekguy\atoum\script();12$atoum->setBootstrapFile('tests/bootstrap.php');13$atoum->setPhpPath('/usr/bin/php');14$atoum->setCodeCoverage();15$atoum->setTestAllDirectory('tests/units/');16$atoum->run();17Fatal error: Uncaught exception 'mageekguy\atoum\exceptions\logic\invalidArgument' with message 'Argument of mageekguy\atoum\script::setTestAllDirectory() must be a string'

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.

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

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