If you have <const name="TESTS_CLEANUP" value="enabled"/>
in your phpunit.xml
(which is the default), Magento starts the test suite with an empty database and runs all setup scripts.
In your case, it looks like the setup script of the custom module runs before the one of Magento_Catalog
which adds the product type to eav_entity_type
.
To overcome this, add Magento_Catalog
as a module dependency.
It seems that it happens in the following observer -
Magento\CatalogSearch\Model\Indexer\Fulltext\Store
(on store_add event which seems to be fired when you save a new store view).
You can see that the observer eventually gets to
Magento\CatalogSearch\Model\Indexer\IndexerHandler::cleanIndex
, where it eventually calls \Magento\CatalogSearch\Model\Indexer\IndexStructure::delete
and \Magento\CatalogSearch\Model\Indexer\IndexStructure::create
, where it eventually gets to the following code that creates the catalogsearch_fulltext_scopeN table -
(class Magento\CatalogSearch\Model\Indexer\IndexStructure)
protected function createFulltextIndex($tableName)
{
$table = $this->resource->getConnection()->newTable($tableName)
->addColumn(
'entity_id',
Table::TYPE_INTEGER,
10,
['unsigned' => true, 'nullable' => false],
'Entity ID'
)->addColumn(
'attribute_id',
Table::TYPE_INTEGER,
10,
['unsigned' => true, 'nullable' => false]
)->addColumn(
'data_index',
Table::TYPE_TEXT,
'4g',
['nullable' => true],
'Data index'
)->addIndex(
'idx_primary',
['entity_id', 'attribute_id'],
['type' => AdapterInterface::INDEX_TYPE_PRIMARY]
)->addIndex(
'FTI_FULLTEXT_DATA_INDEX',
['data_index'],
['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]
);
$this->resource->getConnection()->createTable($table);
}
(where $tableName is catalogsearch_fulltext_scopeN)
Therefore, in order to force the table creation, I suggest to run the following code in your setup script (it's an imitation of Magento\CatalogSearch\Model\Indexer\Fulltext\Store::clearIndex)
$indexerHandlerFactory = \Magento\Framework\App\ObjectManager::getInstance()->get("Magento\\CatalogSearch\\Model\\Indexer\\IndexerHandlerFactory");
$indexerConfig = \Magento\Framework\App\ObjectManager::getInstance()->get("Magento\\Framework\\Indexer\\ConfigInterface");
$dimensionFactory = \Magento\Framework\App\ObjectManager::getInstance()->get("Magento\\Framework\\Search\\Request\\DimensionFactory");
$dimensions = [
$dimensionFactory->create(['name' => 'scope', 'value' => '<YOUR_STORE_VIEW_ID>'])
];
$configData = $indexerConfig->getIndexer('catalogsearch_fulltext');
$indexHandler = $indexerHandlerFactory->create(['data' => $configData]);
$indexHandler->cleanIndex($dimensions);
Best Answer
In
dev/tests/integration/phpunit.xml.dist
there is a setting responsible for clearing cache and DB on each tests execution<const name="TESTS_CLEANUP" value="enabled"/>
. Make sure it is set to true in PHPUnit config which is used when you run tests.Also note, that while it is more reliable to use this option (you get up-to-date environment on each run), it will delay the beginning of tests execution since Magento will be reinstalled in this case (will only affect tests DB).