Magento 2 Get Current Module directory full path programmatically.

You can Retrieve a full path to a directory of a certain type within a module using Magento 2.

Using this article, When you need your current module path using programmatic way, You can fetch the current working module path by given code snippets.

Magento\Framework\Module\Dir and Magento\Framework\Module\Dir\Reader class used for getting the full path of Current modules any directory path like i18n, etc, Model,  Plugin, Helper,  API, view or Controller folder. Continue reading “Magento 2 Get Current Module directory full path programmatically.”

Unit Test for Private and Protected Methods with PHPUnit Magento 2.

PHPUnit used to test your code coverage. You can easily write a Public method test case with PHPUnit.

Writing Unit Test case for private and protected methods in PHP language can cause trouble due to you can’t call private and protected methods directly But they should be tested using a different approach.

Using the ReflectionMethod class invoke() method,
It’s possible to test both methods. In Magento Core code, few methods are tested with Private and Protected test case. Continue reading “Unit Test for Private and Protected Methods with PHPUnit Magento 2.”

How to save uploaded file to specific folder location using Magento 2?

You can save any file type to custom folder location using Magento 2.

If you are working with image, pdf or CSV file and you want to save the file to a specific location using Magento standard way, You have to add a dependency to your __construct function.

The move_uploaded_file() function moves an uploaded file to a new location using core PHP but you can do it Using Magento standard way.

Magento\Framework\Filesystem
Magento\MediaStorage\Model\File\UploaderFactory

Both the class used to save the file to a specific location.

Your phtml file contains input type file,
<input id=”filename” name=”filename” class=”input-file required” type=”file” aria-required=”true”> Continue reading “How to save uploaded file to specific folder location using Magento 2?”