OptionResolver for valid and complete option values

Code
<?php

use Symfony\Component\OptionsResolver\OptionsResolver;

/* 
 * set possible options
 */

$resolver = new OptionsResolver();
$resolver->setDefaults([
    
'enabled' => true,
]);
// array in first param is deprecated since 2.6
$resolver->setAllowedValues('enabled', [truefalse]);
// setOptional is deprecated since 2.6. Use setDefined instead
$resolver->setDefined(['id']);
$resolver->setRequired(['class']);
// array in first param is deprecated since 2.6
$resolver->setAllowedTypes('class''ArrayAccess');

/*
 * options to resolve
 */

$validOpt1 = [
    
'class' => new ArrayObject(),
    
'id' => 3,
];
$validOpt2 = [
    
'class' => new ArrayObject(),
    
'enabled' => false,
];
$invalidOpt1 = [
    
'class' => new EmptyIterator(),
];
$invalidOpt2 = [
    
'class' => new ArrayObject(),
    
'foo' => true,
];

/*
 * resolve options
 */

// valid options
dump($resolver->resolve($validOpt1));
dump($resolver->resolve($validOpt2));

// invalid options
try {
    
$resolver->resolve($invalidOpt1);
} catch (
Exception $e) {
    
dump($e->getMessage());
}

try {
    
$resolver->resolve($invalidOpt2);
} catch (
Exception $e) {
    
dump($e->getMessage());
}
Result
array:3 [
"enabled" => true
"class" => ArrayObject {#370
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
iteratorClass: "ArrayIterator"
storage: []
}
"id" => 3
]

array:2 [
"enabled" => false
"class" => ArrayObject {#375
flag::STD_PROP_LIST: false
flag::ARRAY_AS_PROPS: false
iteratorClass: "ArrayIterator"
storage: []
}
]

"The option "class" with value EmptyIterator is expected to be of type "ArrayAccess", but is of type "EmptyIterator"."

"The option "foo" does not exist. Defined options are: "class", "enabled", "id"."
Used Versions
PHP 7.1, Zend 3.0, Symfony 3.2, Laravel 5.2, PHPUnit 5.6, Doctrine 2.6