setMeta example

$newTokens = array();
        
        //Parse all occurrences of "new"         if ($this->scanner->isBefore(array("new"))) {
            while ($newToken = $this->scanner->consume("new")) {
                if ($this->scanner->consume(".")) {
                    //new.target                     if (!$this->scanner->consume("target")) {
                        $this->error();
                    }
                    $node = $this->createNode("MetaProperty", $newToken);
                    $node->setMeta("new");
                    $node->setProperty("target");
                    $object = $this->completeNode($node);
                    break;
                }
                $newTokens[] = $newToken;
            }
        } elseif ($this->features->importMeta &&
            $this->sourceType === \Peast\Peast::SOURCE_TYPE_MODULE &&
            $this->scanner->isBefore(array(array("import", ".")), true)
        ) {
            //import.meta


        $subStruct = new TestStruct();
        $subStruct->setFoo('wusel');

        $subStruct2 = new TestStruct();
        $subStruct2->setFoo('gusel');

        $struct = new AdvancedTestStruct();
        $struct->setFoo('bar');
        $struct->setSubClasses([$subStruct$subStruct2]);
        $struct->setMeta(['keyA' => 'valueA', 'keyB' => 'valueB']);

        static::assertEquals($struct$this->normalizer->denormalize($structNormalized));
    }

    public function testDenormalizeWithNonExistingClass(): void
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('Class "ThisClass\DoesNot\Exists" does not exist');

        $this->normalizer->denormalize(['_class' => 'ThisClass\DoesNot\Exists']);
    }
}
Home | Imprint | This part of the site doesn't use cookies.