I am run unit test for catalog module. There are error display like below in cmd:

Fatal error: Call to undefined function Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab__() in /var/www/html/magento2/vendor/magento/module-catalog/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/Inventory.php on line 89

And in Test folder error like below:

Magento\Catalog\Block\Adminhtml\Product\Edit\Action\Attribute\Tab\Inventory->getTabLabel() /var/www/html/magento2/vendor/magento/module-catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php:148

what is the cause of issue for error in magento 2.


1 Answer 1


It looks like you run this command line without phpunit.xml.dist:
vendor/phpunit/phpunit/phpunit app/code/Magento/Catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php

You need to use phpunit.xml.dist, that contains attribute bootstrap="./framework/bootstrap.php", because this bootstrap file includes BP . '/app/functions.php', that defines global function __()

To run this one test try to use this command line from the magento project root:

vendor/phpunit/phpunit/phpunit -c dev/tests/unit/phpunit.xml.dist vendor/magento/module-catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php

Also look how to Run tests for a specific module in Magento2

  • hi, my code is inside vendor/magento/module-catalog folder. i want to unit test for core module. Commented Dec 14, 2015 at 10:25
  • @Rakesh Jesadiya, I've updated my answer Commented Dec 14, 2015 at 10:30
  • from magento/bin, we have to run command you have given? Commented Dec 17, 2015 at 9:53
  • You should run it from the magento project root or you should specify absolute paths for the command line, e.g. /var/www/magento2/vendor/phpunit/phpunit/phpunit -c /var/www/magento2/dev/tests/unit/phpunit.xml.dist /var/www/magento2/vendor/magento/module-catalog/Test/Unit/Block/Adminhtml/Product/Edit/Action/Attribute/Tab/InventoryTest.php Commented Dec 17, 2015 at 10:20

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.