Dumplie\Metadata\Tests\Integration\Generic\AssociationTypeTestCase::test_updating_metadata PHP Method

test_updating_metadata() public method

    public function test_updating_metadata()
    {
        $mao = $this->registry->getMAO("product");
        $productId = MetadataId::generate();
        $oldCategoryId = MetadataId::generate();
        $mao->save(new Metadata($productId, "product", ["category" => new Metadata($oldCategoryId, 'category', ["name" => "Fancy stuff"])]));
        $metadata = $mao->getBy(["id" => (string) $productId]);
        $newCategoryId = MetadataId::generate();
        $metadata->category = new Metadata($newCategoryId, 'category', ["name" => "Fashionable"]);
        $mao->save($metadata);
        $metadata = $mao->getBy(["id" => (string) $productId]);
        $this->assertEquals($productId, $metadata->id());
        $this->assertEquals($newCategoryId, $metadata->category->id());
        $this->assertEquals("Fashionable", $metadata->category->name);
    }