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.

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.

Get Customer Id by email Magento 2.

Magento 2 We can get Customer data by customer email id.

You can get the customer id, first name, last name, and other customer specific data by customer email id.

You need to call Magento\Customer\Api\CustomerRepositoryInterface Interface to fetch customer-related data.

We need to call CustomerRepositoryInterface in our class __construct() method.