Skip to content

[4.2] Replace Factory::getApplication() by $this->app in component's controllers#38103

Merged
HLeithner merged 8 commits intojoomla:4.2-devfrom
joomdonation:replace_factory_getapplication_in_controllers
Jun 27, 2022
Merged

[4.2] Replace Factory::getApplication() by $this->app in component's controllers#38103
HLeithner merged 8 commits intojoomla:4.2-devfrom
joomdonation:replace_factory_getapplication_in_controllers

Conversation

@joomdonation
Copy link
Copy Markdown
Contributor

Pull Request for Issue # .

Summary of Changes

In none static methods of component controllers, we should use $this->app to get application object instead of using Factory::getApplication(). This PR just makes that change.

Testing Instructions

I hope code review would be enough. Otherwise, I will have to split this simple PR to multiple small PRs for real user testing.

Actual result BEFORE applying this Pull Request

Works !

Expected result AFTER applying this Pull Request

Works !

Documentation Changes Required

None

@laoneo laoneo added the Maintainers Checked Used if the PR is conceptional useful label Jun 20, 2022
@laoneo
Copy link
Copy Markdown
Member

laoneo commented Jun 20, 2022

Restarted drone. Wondering if the system test installation is failing because of the pr or just a hickup.

@richard67
Copy link
Copy Markdown
Member

Restarted drone. Wondering if the system test installation is failing because of the pr or just a hickup.

Wondering about the same. But I haven't found anything in the log or the screenshot from the test results telling what it could be.

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Jun 21, 2022

The restart from yesterday and the branch update now were both successfully.

@richard67
Copy link
Copy Markdown
Member

The restart from yesterday and the branch update now were both successfully.

Maybe it depends on the moon phase 😄 .

@brianteeman
Copy link
Copy Markdown
Contributor

I really appreciate all the work you are and @laoneo are doing but I really think that it is far too late in the release process of 4.2 to be making these changes.

@RickR2H
Copy link
Copy Markdown
Member

RickR2H commented Jun 21, 2022

I have tested this item ✅ successfully on 83e9eae


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38103.

@laoneo
Copy link
Copy Markdown
Member

laoneo commented Jun 21, 2022

I really appreciate all the work you are and @laoneo are doing but I really think that it is far too late in the release process of 4.2 to be making these changes.

I think this is up to the release lead to decide. And nobody says that this needs to go into 4.2. But thats the branch where this kind of changes should be done to atm.

@viocassel
Copy link
Copy Markdown
Contributor

I have tested this item ✅ successfully on 83e9eae


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38103.

@richard67
Copy link
Copy Markdown
Member

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38103.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jun 21, 2022
@HLeithner HLeithner merged commit e4f622c into joomla:4.2-dev Jun 27, 2022
@HLeithner
Copy link
Copy Markdown
Member

Thanks

@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jun 27, 2022
@joomdonation joomdonation deleted the replace_factory_getapplication_in_controllers branch June 27, 2022 16:01
@Quy Quy added this to the Joomla 4.2.0 milestone Jun 27, 2022
@trananhmanh89
Copy link
Copy Markdown
Contributor

Could anyone tell me why do we have to make this change? And Factory::getApplication() will be bad practice ?

@wilsonge
Copy link
Copy Markdown
Contributor

So inside the controller we want to take better advantage of dependency injection. This allows us to create significantly better unit tests over the controllers and therefore improve both the quantity and quality of tests by creating mocks. Additionally injecting like this allows us to take better advantage of the Dependency injection container.

The static factory settings conversely are more difficult to mock across multiple tests, mean its harder to utilise the DIC. Furthermore by making this dynamic it improves our ability to use the same controller in different applications (as API starts to become more of a first class citizen this will become more and more clear I think)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Maintainers Checked Used if the PR is conceptional useful

Projects

None yet

Development

Successfully merging this pull request may close these issues.