Question

I'm facing a strange issue (on Magento EE 1.14.2.1) where I cannot retrieve EAV product data after setting up a fixture.

My test:

/**
 * @loadFixture
 */
public function testExample()
{
    $product = Mage::getModel('catalog/product')->load(1);
    var_dump($product->getSku(), $product->getData('name'), $product->getPrice());
    exit;
}

My fixture:

# File: fixtures/testExample.yaml
eav:
    catalog_product:
        - entity_id: 1
          sku: 12345/RED/
          name: Some configurable
          attribute_set_id: 4
          entity_type_id: 4
          type_id: configurable
          price: 49.99

I'm using exit to prevent EcomDev_PHPUnit from clearing the database tables after the test completes. At the moment my output from this is:

string(10) "12345/RED/"
NULL
NULL

I can access the product data (e.g. sku) that is stored in catalog_product_entity, but nothing from the EAV tables.

I've examined the database after this fixture is loaded, and the attributes for example name and price all exist in their respective EAV tables (catalog_product_entity_varchar and catalog_product_entity_decimal).

The attributes exist in the test database and are configured correctly for the product entity ID and attribute set.

When using getData() or getName() for example, they always return null.

Am I missing something?

Was it helpful?

Solution 2

So to re-iterate, my symptoms were:

  • If I ->load(1) the product I only get the values that exist in catalog_product_entity
  • If I ->setId(1)->load() I only get the EAV attribute values, not the main table values
  • If I run a collection and ->getFirstItem() with an entity ID filter on it, I get all attributes

After a bit of digging around and examining SQL query logs, I actually found that my eav_entity_attribute table in the PHPUnit test database was missing its entries for all core Magento EAV attributes. This table is generally not written to or deleted from when running EcomDev PHPUnit tests, unless you have an attribute installer script, or you fixture this table.

My assumption is that at some point I had created a fixture for this table which would have cleared the table, and it would never have been regenerated.

I've refreshed this table from my main Magento database and everything works now.

If anybody else comes into this same problem, my quick fix was to run the following SQL query:

SET foreign_key_checks = 0;
# Refresh the entity attribute records from your main Magento database
TRUNCATE your_unit_test_db.eav_entity_attribute;
INSERT INTO your_unit_test_db.eav_entity_attribute SELECT * FROM your_main_magento_db.eav_entity_attribute;
SET foreign_key_checks = 1;

OTHER TIPS

Regarding the product fixture, your initial test setup looks fine.

It's probably the stores fixture that is missing but vital for the EAV data to be loaded correctly.

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