testDependentOptionIsRequired(); $this->testDependentOptionIsNotRequired(); $this->testDependentOptionIsProvided(); } public function testDependentOptionIsRequired(): void { $resolver = new OptionsResolver([ Option::string('auth_method'), Option::string('password'), ]); $resolver->addRequiredIf('password', 'auth_method', 'credentials'); $this->expectException(\InvalidArgumentException::class, function () use ($resolver) { $resolver->resolve(['auth_method' => 'credentials']); }); } public function testDependentOptionIsNotRequired(): void { $resolver = new OptionsResolver([ Option::string('auth_method'), Option::string('password')->setOptional(), ]); $resolver->addRequiredIf('password', 'auth_method', 'credentials'); $options = $resolver->resolve(['auth_method' => 'token']); $this->assertNull($options['password']); } public function testDependentOptionIsProvided(): void { $resolver = new OptionsResolver([ Option::string('auth_method'), Option::string('password'), ]); $resolver->addRequiredIf('password', 'auth_method', 'credentials'); $options = $resolver->resolve(['auth_method' => 'credentials', 'password' => 'secret']); $this->assertArrayHasKey('password', $options); $this->assertStrictEquals('secret', $options['password']); } }