Thursday, June 8, 2017

Can't save Magento2 product in integration test

Leave a Comment

I am working on an integration test for a project called the Magento2 Configurator.

I'm using the latest version of Magento CE.

It need to programmatically set up some fixture products, however Magento doesn't seem to save the product to the database.

I have a branch and an excerpt of the code is below:

    // 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 

The problem is, is that what I run the test with

/var/www/magento2/dev/tests/integration$ ../../../vendor/bin/phpunit --testsuite "magento2-configurator" --filter="testShouldCreateNewCatalogPriceRulesFromYamlFile" 

And check the database using mysqldump, nothing seems to be entered.

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` 

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment