2

I have created 2 new product attributes that are mandatory (required), "vendor_id" and "delivery_country".

After creating this two attributes the integration tests are failing.

I executed the testes just for one module to see what is happening:

<directory suffix="Test.php">testsuite/Magento/AdvancedCheckout</directory>

When running the integrations tests for this module it gives me fatal error:

Magento\AdvancedCheckout\Controller\CartTest::testConfigureFailedActionWithDownloadableProduct

Magento\Eav\Model\Entity\Attribute\Exception: The value of attribute "vendor_id" must be set in /vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:111

I have noticed that this module is using this two files for products:

dev/tests/integration/testsuite/Magento/Downloadable/_files/product_downloadable.php

and

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple.php

I added the new attributes in the above files, after executing tests again they are passing.

The problem is that there are many files that are creating products for integration tests and I don't see as a solution to modify this files.

Is there a way to set this new attributes on all the products that are created for integration tests without modifying all the fixture files.

  • You are adding this attribute by using custom module? – Shashank Gupta Feb 27 '18 at 13:11
  • Yes, custom module and the attributes where created programmatically. – Sebastian Feb 27 '18 at 13:33
2

You cannot run the core test suite with a customized build like this. But this is not their purpose anyways. The core integration test suite is there to ensure that the core modules work together as intended and to prevent bugs in Magento itself.

If you want to run an integration test for the checkout that is adapted to your changes, you are free to reuse parts of the core tests, but you will have to make adjustments like adding values for custom required attributes in the used fixtures.

But do not try to recreate integration tests just for core functionality. Create tests that ensure, that your code works.

For high level "Magento still works" tests, functional tests are more appropiate than integration tests. That's also why the new Magento Functional Test Framework (MFTF) will give us extensible core tests. This one is meant to be run on custom builds.

  • I understand that the basic integration test package is there to make sure that the core modules work as intended and to prevent errors in Magento itself. But it seams strange to me that if you add a custom mandatory product attribute to your build, you can no longer run the integration test. When integration tests run Magento is installed on the empty db and it creates also the new attributes created via script. Do you have any suggestion how to isolate the creation of attributes for integration tests only? I don't want to create core integration tests I just want to run the current ones. – Sebastian Mar 19 '18 at 15:23
0

This above error means your fixture files are not loading at the time when your test runs or db is not isolated, In my opinion you can give try by doing following steps :

rootdir\dev\tests\integration\phpunit.xml.dist rename to phpunit.xml add following code

<testsuite name="Third Party Integration Tests">
            <directory>../../../app/code/*/*/Test/Integration</directory>
            <directory>../../../vendor/*/module-*/Test/Integration</directory>
            <exclude>../../../app/code/Magento</exclude>
            <exclude>../../../vendor/magento</exclude>
        </testsuite>

Then your Integration test location should be rootdir/app/code/Vendor/ModuleName/Tests/Integration/

Open Terminal Run command from magento root directory :

cd dev/tests/integration 

php ../../../vendor/bin/phpunit --testsuite "Third Party Integration Tests"

Make Sure following annotation definition in your test Chckout this link for better understanding

In my opinion you need to isolate your db before runing the test and define the value of custom attribute in fixture file and loadFixture , Also make sure your fixture file is running and taking a correct value .Take a look on following example :

Integration test file :

Class XYZTest extends \PHPUnit\Framework\TestCase
{

 public static function loadFixture()
    {
        include __DIR__ . '/../_files/product_downloadable_create_with_setting_custom_attribute_value.php';

   /**
     * @magentoDbIsolation enabled
     * @magentoAppIsolation enabled
     * @magentoDataFixture loadFixture
     */
    public function testYourFunctionName()
    {
      //use above annotation as per your need 
      .................
      .......................
    }

    }
}

Hopefully this will help you .

  • Use the same code for setting a custom attribute in fixture files as you are using in production code. – Shashank Gupta Feb 27 '18 at 14:19
  • I see your point, but this is about Magento Core integration test that are failing after you add a custom mandatory product attribute to the system, I want to run all the core tests, you are suggesting to exclude core tests. – Sebastian Feb 27 '18 at 14:19
  • But your code is running fine individually , did you checked ? – Shashank Gupta Feb 27 '18 at 14:21
  • Lets say we have a CI environment that is running all the tests on a magento 2 out of the box with no custom code. The integration tests are passing. After I add a custom mandatory attribute to the product the CI is failing. I don't want to skip the core tests just because I added a custom mandatory attribute. – Sebastian Feb 27 '18 at 14:23
  • In my opinion , run the test first in above way , If it is runing perfectly then try with all to together using Magento default ssh command line command , secondly It will take to much time to run so some time MySQL suspend the the process , So you need to configure your server accordingly , Otherwise it should run correctly but takes much time , that's why Individual run suggested . – Shashank Gupta Feb 27 '18 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.