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?”

How to write PHPUnit Test for a module in Magento 2?

All the Core module in Magento natively comes with Unit and Integration Test.

As a professional Developer, When you create any module for your project, You should have to write Unit Test for your module code to validate your code is errorless.

Write a Unit test for your module, Gives guarantee your code is bug-free with Find problems earlier before going live and if any error available for a code, you can update the code before code is going to a production server. Continue reading “How to write PHPUnit Test for a module in Magento 2?”

How to check the status of each test in PHPUnit Test using CLI?

You can check the status of each Unit Test in PHP using single character output.

For each test run, the PHPUnit command-line tool prints one character to indicate result(status) of each test, Continue reading “How to check the status of each test in PHPUnit Test using CLI?”