Magento2: Unit test fails after fresh installation

Created on 4 Oct 2017  路  7Comments  路  Source: magento/magento2

I have freshly installed Magento 2.2. The first thing I do is running unit tests. I have got one error.

Preconditions

  1. Magento 2.2
  2. PHP 7.0
  3. MySQL 5.7.19, for Linux (x86_64)

Steps to reproduce

  1. Install Magento with composer
  2. Run this command vendor/bin/phpunit -c dev/tests/unit/phpunit.xml.dist
  3. You get the error

Expected result

  1. To pass all the unit tests

Actual result

  1. You got the following error:
Magento\Setup\Test\Unit\Module\Di\Code\Reader\FileClassScannerTest::testClassKeywordInMiddleOfFile
Magento\Setup\Module\Di\Code\Reader\InvalidFileException: The file "/var/www/html/magento2-install1" does not exist or is not a file

/var/www/html/magento2-install1/setup/src/Magento/Setup/Module/Di/Code/Reader/FileClassScanner.php:39
/var/www/html/magento2-install1/setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/FileClassScannerTest.php:213


When I look at this file setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/FileClassScannerTest.php, I am seeing the following test.

public function testClassKeywordInMiddleOfFile()
{
    $filename = __DIR__
        . '/../../../../../../../../../..'
        . '/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php';
    $filename = realpath($filename);
    $scanner = new FileClassScanner($filename);
    $result = $scanner->getClassNames();

    self::assertCount(1, $result);
}

This is interesting that there is not any file in app/code, since the file it is looking for inside vendor directory.

Fixed in 2.3.x Cannot Reproduce Clear Description Format is valid

Most helpful comment

This can be reproduced by installing Magento 2.2 via composer.

The test will look for:
app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

It won't find the file, because it is located at:
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

All 7 comments

@bnymn, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. If you'd like to update it, please reopen the issue.
We tested the issue on 2.2.0

This can be reproduced by installing Magento 2.2 via composer.

The test will look for:
app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

It won't find the file, because it is located at:
vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

Confirmed what @vanpoppel says. Please reopen issue @magento-engcom-team

I would like to know if this test is intended for use on a Magento2 installed via composer. When you install Magento2 by creating a clone from the Magento2 repository you won't have this problem. But (I hope) people only do this to contribute to Magento2.

Is a developer supposed to be able to run all unit tests when installed via composer? Or only the ones they write themselves?

@vanpoppel I think that a developer must have the ability to run all unit tests, because sometimes we are writing plugins which changes the behavior of core modules. In this case, we need to make sure that everything is working just fine.

Hi @bnymn. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1287 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming patch release.

As #12419 if you want to avoid the problem (but not fix the error)

In /dev/tests/unit/phpunit.xml.dist exlude FileClassScannerTest.phptest

<testsuite name="Magento Unit Tests">
       .....

<exclude>../../../setup/src/Magento/Setup/Test/Unit/Module/Di/Code/Reader/FileClassScannerTest.php</exclude>
    </testsuite>
Was this page helpful?
0 / 5 - 0 ratings