Phpmd Error: The class uses sessions or cookies while not being a part of HTML Presentation layer in Magento 2.

In Magento 2, You are trying to commit the module with PHP Code standard tools GrumPHP and your module have an issue related to Sessions or cookies that are not used in the Presentation layer at that time you are facing the error like this,

The class uses sessions or cookies while not being a part of HTML Presentation layer.

You have to fixed PHPMD error by adding SuppressWarnings before the class name. Continue reading “Phpmd Error: The class uses sessions or cookies while not being a part of HTML Presentation layer in Magento 2.”

Phpunit test for factory collection in Magento 2.

In Magento 2, All the core module uses PHPUnit test for verify code is working or not with an automated PHP unit test framework.

As a professional developer, You should write Unittest for each of your module’s logical file.

I will generate a  Unit test for Factory Pattern where function return collection based on custom conditions on collection factory. Continue reading “Phpunit test for factory collection in Magento 2.”

Add Secret Key to URLs in Magento 2.

Magento is delivering superior security to all of their clients and has been actively investigating the root cause of the reported issue and try to fix for security issue found in the system.

To prevent CSRF attacks for Magento backend you need to enable Add Secret Key to URLs, Out of the box, Magento provides this feature as enabled.

To reduce potential CSRF attacks in Magento 2 do the following steps. Continue reading “Add Secret Key to URLs in Magento 2.”