Skip to content
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

Closed
wants to merge 43 commits into from
Closed

Conversation

laoneo
Copy link
Member

@laoneo laoneo commented Jun 30, 2017

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 code

$app = JFactory::getApplication('site');
$app = JFactory::getApplication('administrator');
echo $app->getName();
// Returns site and not administrator

will 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.

@@ -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();
Copy link
Contributor

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

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();
}
for example)

@laoneo
Copy link
Member Author

laoneo commented Aug 17, 2017

If you can come up with an approach that makes the container accessible

At least I would make it available in another class like \Joomla\CMS\Container\ContainerFactory which is deprecated and contains the container set up code and getContainer.

@mbabker
Copy link
Contributor

mbabker commented Aug 17, 2017

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.

@laoneo
Copy link
Member Author

laoneo commented Aug 18, 2017

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.
I did your reccomendations, so @wilsonge what do you think, ready to merge or still some concerns?

# 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
@laoneo
Copy link
Member Author

laoneo commented Feb 2, 2018

Closing this one in favor of smaller pr's. Guess we stick with JFactory::getContainer()so there is no need to have an effort to move it into it's own file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants