-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.0] Sync app setup #16918
[4.0] Sync app setup #16918
Conversation
…e-container-from-factory
130b5f7
to
4bdd7c5
Compare
@@ -27,6 +27,8 @@ protected function setUp() | |||
|
|||
// Some tests are affected by the output of the logger, so we clear the logger here. | |||
JLog::setInstance(null); | |||
|
|||
JFactory::$application = $this->getMockCmsApp(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are setting factory instances in tests you need to save and restore the factory state in setUp/tearDown methods otherwise you 'contaminate' other tests (see
joomla-cms/tests/unit/suites/libraries/joomla/document/image/JDocumentImageTest.php
Lines 24 to 44 in 16d5a29
protected function setUp() | |
{ | |
parent::setUp(); | |
$this->saveFactoryState(); | |
JFactory::$application = $this->getMockWeb(); | |
$this->object = new JDocumentImage; | |
} | |
/** | |
* Tears down the fixture, for example, closes a network connection. | |
* This method is called after a test is executed. | |
*/ | |
protected function tearDown() | |
{ | |
$this->restoreFactoryState(); | |
parent::tearDown(); | |
} |
At least I would make it available in another class like |
That part's just aesthetics. What's the real difference between being in the centralized factory and it being a random class elsewhere? It's still going to be global singleton and static methods. |
I would like to get rid of JFactory, so adding more stuff to it would be a wrong signal. Having it in a new class would make it more clear. We can even call it InternalContainerFactory to make it cristal clear that it is only a transition class. But this can be done on a later point if required. |
…app-setup # Conflicts: # build/helpTOC.php # libraries/src/CMS/Application/CliApplication.php
# Conflicts: # administrator/components/com_banners/Model/Tracks.php # administrator/components/com_categories/Model/Category.php # administrator/components/com_fields/Model/Field.php # administrator/components/com_installer/Model/Install.php # administrator/components/com_languages/Model/Language.php # administrator/components/com_menus/Model/Item.php # administrator/components/com_menus/Model/Items.php # administrator/components/com_menus/Model/Menu.php # administrator/components/com_modules/Model/Module.php # administrator/components/com_modules/Model/Select.php # administrator/components/com_plugins/Model/Plugin.php # administrator/components/com_tags/Model/Tag.php # administrator/components/com_templates/Model/Style.php # administrator/components/com_templates/Model/Template.php # administrator/components/com_users/Model/Debuggroup.php # administrator/components/com_users/Model/Debuguser.php # administrator/components/com_users/Model/Users.php # cli/deletefiles.php # cli/garbagecron.php # cli/update_cron.php # components/com_config/Model/Modules.php # components/com_contact/Model/Contact.php # components/com_content/Model/Archive.php # components/com_content/Model/Article.php # components/com_content/Model/Category.php # components/com_newsfeeds/Model/Newsfeed.php # components/com_tags/Model/Tags.php # installation/application/app.php # libraries/src/Application/CliApplication.php # libraries/src/Factory.php # libraries/src/Model/Model.php # libraries/src/Service/Provider/Application.php # libraries/src/Service/Provider/Session.php # plugins/installer/folderinstaller/tmpl/default.php
Closing this one in favor of smaller pr's. Guess we stick with |
Summary of Changes
With the introduction of the
CMSApplicationInterface
in #16499 and the adjustments of the cli apps in #16540, this is the next step to harmonize the front controllers. The installation, site, administrator and all cli front controllers do have now the same way of set up and app access. All are loading the container init script, modifying the container and getting the app out of it.JFactory::getApplication cleanup
Now
JFactory::getApplication();
doesn't take any arguments anymore and will return always the global application object which must be set by the front controller during the set up phase. The problem on that part in J3 is that the codewill always return the site app, despite the administrator app is requested. This can be done now trough
JFactory::getApplication()->getContainer()->get('SiteApplication');
which will return a site application even on the back end.Mockable DI container
The DI container should be fetched trough the app as well, to have only one way to access it. It is possible now to mock it properly. A first step is done by creating the required functions in the test base classes. In a next step, the container needs to be set up in the appropriate test classes.
Testing Instructions
Browse around in the front and back end.
Expected result
All should work as expected.
Actual result
All is working as expected.
Documentation Changes Required
The changes in
JFactory::getApplication()
do need to be documented.