1

I create simple unit test with object manager with class name

$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this)

and object Name ModuleList like

$moduleList = $objectManager->getObject(ModuleList::class);

 print_r($moduleList->getAll());

but not getting all module list

this my unitTest file give below

namespace NameSpaceModule\Test\Test\Unit;
use Magento\Framework\Module\ModuleList;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\TestCase;
class SampletTest extends TestCase
{
 private $moduleName = 'NameSpaceModule_Test';
 public function testTheModuleIsConfiguredAndEnabled(){
 /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager $objectManager */
 $objectManager = new ObjectManager($this);
 /** @var ModuleList $moduleList */
 $moduleList = $objectManager->getObject(ModuleList::class);
 print_r($moduleList->getAll());
 }
}
asked Dec 7, 2017 at 12:04

1 Answer 1

2

Unit tests are supposed to test your code in isolation. In the Magento unit test suite, the application is not instantiated, that means there is no database, no module configuration etc. Even using the object manager is not recommended. The unit test object manager helper was only introduced for old legacy core code.

What you are trying to test would be an integration test, not a unit test. You test how the module is integrated in Magento. In integration test the application is instantiated, with a test database and everything.

Just one more remark about your specific test: in integration tests, all modules are enabled automatically. So you will effectively just test if the module exists and can be enabled.

answered Dec 9, 2017 at 18:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.