Skip to content

[Issue] Unit Test / Deprecate / ObjectManager Helper #29346

Closed
@m2-assistant

Description

@m2-assistant

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

  1. Need for mocking all the dependencies will make Developer think twice before introducing another few of dependencies.
  2. 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.
  3. 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

Component: TestFrameworkFixed in 2.4.xThe issue has been fixed in 2.4-develop branchIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentPriority: P4No current plan to fix. Fixing can be deferred as a logical part of more important work.Progress: doneReported on 2.4.0Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S4Affects aesthetics, professional look and feel, “quality” or “usability”.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions