I am trying to create a integration test to check if my module is enabled or not.

Following is the code in my test class


namespace Anshu\Learning\Test\Integration;

use Magento\Framework\App\DeploymentConfig;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Module\ModuleList;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;

class LearningConfigTest extends TestCase
    private $moduleName = 'Anshu_Learning';

    public function testIsModuleConfiguredAndEnabled()
         * @var ObjectManager $objectManager
        $objectManager = new ObjectManager($this);

         * @var DirectoryList $dirList
        $dirList = $objectManager->getObject(DirectoryList::class, ['root' => BP]);

         * @var DeploymentConfig\Reader $configReader
        $configReader = $objectManager->getObject(DeploymentConfig\Reader::class, ['dirList' => $dirList]);

         * @var DeploymentConfig $deploymentConfig
        $deploymentConfig = $objectManager->getObject(DeploymentConfig::class, ['reader' => $configReader]);

         * @var ModuleList $moduleList
        $moduleList = $objectManager->getObject(ModuleList::class, ['config' => $deploymentConfig]);

        $this->assertTrue($moduleList->has($this->moduleName), 'Module is not enabled');

While running the test I am getting error message Use of undefined constant BP - assumed 'BP' (this will throw an Error in a future version of PHP)

And when I am changing BP to DirectoryList::ROOT then I am getting following error message

array_keys() expects parameter 1 to be array, null given

PHP version is 7.2

May someone can help me to figure out and fix the issue.

1 Answer 1


Try to import this class Magento\TestFramework\ObjectManager instead of Magento\Framework\TestFramework\Unit\Helper\ObjectManager.

Then initialize ObjectManager by this:

$objectManager = ObjectManager::getInstance();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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