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

test_updating_metadata_with_altered_object() public method

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