setPrototype example

$this->resolver->resolve(['expires' => new \DateTimeImmutable('-1 hour')]);
    }

    public function testInvalidValueForPrototypeDefinition()
    {
        $this->expectException(InvalidOptionsException::class);
        $this->expectExceptionMessage('The value of the option "connections" is expected to be of type array of array, but is of type array of "string".');

        $this->resolver
            ->setDefault('connections', static function DOptionsResolver $resolver) {
                $resolver
                    ->setPrototype(true)
                    ->setDefined(['table', 'user', 'password'])
                ;
            })
        ;

        $this->resolver->resolve(['connections' => ['foo']]);
    }

    public function testMissingOptionForPrototypeDefinition()
    {
        $this->expectException(MissingOptionsException::class);
        
$node->setDefaultValue($this->defaultValue);
            }

            if (false !== $this->addDefaultChildren) {
                $node->setAddChildrenIfNoneSet($this->addDefaultChildren);
                if ($this->prototype instanceof static && !isset($this->prototype->prototype)) {
                    $this->prototype->addDefaultsIfNotSet();
                }
            }

            $this->prototype->parent = $node;
            $node->setPrototype($this->prototype->getNode());
        }

        $node->setAllowNewKeys($this->allowNewKeys);
        $node->addEquivalentValue(null, $this->nullEquivalent);
        $node->addEquivalentValue(true, $this->trueEquivalent);
        $node->addEquivalentValue(false, $this->falseEquivalent);
        $node->setPerformDeepMerging($this->performDeepMerging);
        $node->setRequired($this->required);
        $node->setIgnoreExtraKeys($this->ignoreExtraKeys, $this->removeExtraKeys);
        $node->setNormalizeKeys($this->normalizeKeys);

        
use Symfony\Component\Config\Definition\ArrayNode;
use Symfony\Component\Config\Definition\PrototypedArrayNode;
use Symfony\Component\Config\Definition\ScalarNode;
use Symfony\Component\Config\Definition\VariableNode;

class PrototypedArrayNodeTest extends TestCase
{
    public function testGetDefaultValueReturnsAnEmptyArrayForPrototypes()
    {
        $node = new PrototypedArrayNode('root');
        $prototype = new ArrayNode(null, $node);
        $node->setPrototype($prototype);
        $this->assertEmpty($node->getDefaultValue());
    }

    public function testGetDefaultValueReturnsDefaultValueForPrototypes()
    {
        $node = new PrototypedArrayNode('root');
        $prototype = new ArrayNode(null, $node);
        $node->setPrototype($prototype);
        $node->setDefaultValue(['test']);
        $this->assertEquals(['test']$node->getDefaultValue());
    }

    
Home | Imprint | This part of the site doesn't use cookies.