我正在为名为Magento2 Configurator的项目进行集成测试。
我正在使用最新版本的Magento CE。
需要以编程方式设置一些夹具产品,但Magento似乎并未将产品保存到数据库中。
我有一个branch,下面的代码摘录如下:
// given a yaml file
$yamlParser = new Parser();
$testCatalogPriceRules = $yamlParser->parse(file_get_contents($this->testCatalogPriceRulesYamlPath), true);
// and a sample product
/** @var \Magento\Catalog\Model\Product */
$productModel = Bootstrap::getObjectManager()
->get('\Magento\Catalog\Model\Product');
$productModel->setName("Cool 123");
$productModel->setAttributeSetId(1);
$productModel->setShortDescription("Cool 123");
$productModel->setWebsiteIds(array(1));
$productModel->setVisibility(4);
$productModel->setDescription("Cool 123");
$productModel->setSku("SKU");
$productModel->save();
// and a customer group
// when we run the AdminRoles component
$this->catalogPriceRulesComponent->processData($testCatalogPriceRules);
// then it should enter new catalog price rules into the database
问题是,我用
运行测试/var/www/magento2/dev/tests/integration$ ../../../vendor/bin/phpunit --testsuite "magento2-configurator" --filter="testShouldCreateNewCatalogPriceRulesFromYamlFile"
使用mysqldump检查数据库,似乎没有输入任何内容。
ubuntu@ubuntu-xenial:/var/www/magento2/var/log$ mysqldump -u root -p magento_integration_tests | grep -i "Cool" -C5
mysqldump: [Warning] Using a password on the command line interface can be insecure.
-- Dumping data for table `url_rewrite`
--
LOCK TABLES `url_rewrite` WRITE;
/*!40000 ALTER TABLE `url_rewrite` DISABLE KEYS */;
INSERT INTO `url_rewrite` VALUES (1,'cms-page',1,'no-route','cms/page/view/page_id/1',0,1,NULL,1,NULL),(2,'cms-page',2,'home','cms/page/view/page_id/2',0,1,NULL,1,NULL),(3,'cms-page',3,'enable-cookies','cms/page/view/page_id/3',0,1,NULL,1,NULL),(4,'cms-page',4,'privacy-policy-cookie-restriction-mode','cms/page/view/page_id/4',0,1,NULL,1,NULL),(5,'product',1,'cool-123.html','catalog/product/view/id/1',0,1,NULL,1,NULL);
/*!40000 ALTER TABLE `url_rewrite` ENABLE KEYS */;
UNLOCK TABLES;
--
-- Table structure for table `variable`