Question

I managed to put up a EcomDev_PHPUnit_Test_Case with this:

public function testGetModelMemoryTrace() {
    $model = Mage::getModel('catalog/product');
    $product = $model->load(10);
    $this->assertEquals($product->getId(), 10);
    $parentProduct = $model->load(4);
    $this->assertEquals($product->getId(), 10); //here getId() is actually 4...
}

This test fails for me in the last assert. Is this an expected effect ? To clarify, the second load alters first reference to object id 10.

Thank you.

Was it helpful?

Solution

$model->load doesnt return a new instance. It returns itself. So $model, $product and $parentProduct is actually the same instance.

OTHER TIPS

Problem is here... When you load prroduct at second time the yoy took variable $parentProduct and you are passing variable $product.

$product contain reference of product id 10 and

$parentProduct contain reference of product id 4.

Thant's why you are getting 10 as product id at second time. So either need to change $product->getId() to $parentProduct->getId() or when you are loading product at second time for id 4 then re-assign it to variable $product.

Hope this will help you.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top