Skip to content

PHPStan Does Not Find \Magento\TestFramework\Helper\Bootstrap #31

@sprankhub

Description

@sprankhub

Preconditions

  1. Magento 2.3.4
  2. PHP 7.2
  3. bitexpert/phpstan-magento 0.1.0

Steps to reproduce

  1. Create an example integration test in your module, e.g. \Company\Module\Test\Integration\ExampleTest:

     <?php
     
     declare(strict_types=1);
     
     namespace Company\Module\Test\Integration;
     
     use Magento\TestFramework\Helper\Bootstrap;
     use PHPUnit\Framework\TestCase;
     
     class ExampleTest extends TestCase
     {
         protected function setUp(): void
         {
             Bootstrap::getObjectManager();
         }
     }
    
  2. Run vendor/bin/phpstan analyze --level=8 src/Company/Module/Test/Integration.

Expected result

  1. No issues are found.

Actual result

  1. One issue is found:

     Call to static method getObjectManager() on an unknown class Magento\TestFramework\Helper\Bootstrap
    

Workaround

Ignore the error in your phpstan.neon:

ignoreErrors:
    - '#Call to static method getObjectManager\(\) on an unknown class Magento\\TestFramework\\Helper\\Bootstrap.#'

The same issue occurs when you try to use the alternative \Magento\Framework\App\ObjectManager::getInstance, so this can unfortunately not be used as a workaround.

Idea

Do we need to add another custom autoloader for Magento\TestFramework?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions