Description
This issue is automatically created based on existing pull request: #29272: Unit Test / Deprecate / ObjectManager Helper
Summary (*)
Magento 2.4-develop
During the Magento 1 to Magento 2 migration, the rush around forced Magento developers to make some compromises.
Last month we finally said Good Bye to Magento 1, but we still fight against the legacy we inherited.
One of the Ancient Artifacts is \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
which purpose was to mock all the dependencies that were not necessary to mock for specific Unit Tests. That enabled developers to introduce ugly classes with a few of dependencies.
In my personal opinion 2020 is about the time to stop this ridiculous practice and give up with using ObjectManager for instantiating classes under test and replace that with new
keyword in Unit Tests.
Reason behind it
- Need for mocking all the dependencies will make Developer think twice before introducing another few of dependencies.
- Introducing new backwards-incompatible dependency to the class will result in Unit Tests failure, thus will point out Developer that he introduced the backwards-incompatible change.
- ObjectManager hides the ugly complexity of Magento classes.
Examples (*)
PR makes an ugly world of Magento Unit Tests a slightly better place.
Proposed solution
Metadata
Metadata
Assignees
Labels
Type
Projects
Status