Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
simpletest.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
9 May 2014 at 21:38 UTC
Updated:
19 Jan 2015 at 18:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
damiankloip commentedComment #3
damiankloip commentedNeed an actual account proxy object! I was certain I already did this change in the current user issue, maybe it got lost somewhere along the way.
Comment #5
damiankloip commentedWe either wait on https://drupal.org/node/2263329 or merge it here.
Comment #6
blueminds commentedreroll
Comment #8
damiankloip commentedThe patch in #3 still applied fine?
Comment #9
blueminds commentedYes, without any problem.
Comment #10
damiankloip commentedSo what's the 'reroll' for? :)
Comment #11
blueminds commentedI get your point :)
Comment #12
damiankloip commented#2263329: CommentDefaultFormatterCacheTagsTest just works because nothing uses AccountProxyInterface in HEAD is in.
Comment #13
damiankloip commented6: 2263339-6.patch queued for re-testing.
Comment #15
damiankloip commentedFixed those failures. Adding current_user service to the setup in Drupal\system\Tests\KeyValueStore\StorageTestBase.
Comment #16
dawehnerIs there a simple reason why we have to construct the object for yourself and can't just use $this->container->get('current_user')->setAccount...?
Comment #17
damiankloip commentedSimple reason is this test extends from UnitTestBase, not DrupalUnitTestBase. So there is no container ready like normal.
Comment #18
dawehnerOh right.
Comment #19
znerol commentedIs it really necessary to replace the
current_userservice here? Wouldn't it be enough to set the account on the proxy, in the same way like inrestoreEnvironment?Comment #20
damiankloip commentedBut just above prepareEnvironment a new container is created:
So not sure how that would already have an account proxy object set on it?
Comment #21
znerol commentedI see.
What happens if this is removed entirely? That seems to affect the original container which is not supposed to be modified during the test.
Comment #22
damiankloip commentedSorry but that is not a problem of this issue IMO. This is just converting the instances. That hunk is just a straight swap. If we think restoreEnvironment is doing something wrong. I think we should talk about that in a new concentrated issue?
Comment #23
znerol commentedRereading the patch I still do not like these changes. Most consumers of the
current_userjust need theAccountInterfacepart of it. TheAccountProxyInterfacepart is only important for those services which are supposed to swap out the user instances (i.e. authentication).Comment #24
damiankloip commentedWell, also, e.g. the Cron class uses this. Just because tests do not rely on this now does not mean they wont in the future. If we usually have an AccountProxy in the container, we should also have this in the container for tests too. Otherwise, first implementation that needs it in there will have to make this change anyway. You want as few discrepancies in the test env as possible, no? You could encounter subtle issues that tests may not catch if the real life implementation is actually using the proxy and not just a straight up account.
Comment #25
dawehnerI really doubt that it is worth to fight here ...
Comment #26
znerol commentedEverything which calls
AccountProxyInterface::setAccount()is potentially very dangerous. Only those services which really need to change the user should declare a dependency onAccountProxyInterface. All the others should stick withAccountInterface, therefore it is not clear to me why it is desirable to change the mocks inCommentLockTest,LocaleLookupTestandViewUIObjectTest.Perhaps it makes sense to have an
AccountProxyin DUTB. But even there I think it would be legit to delegate the responsibility of setting up a realAccountProxyto the tests which cannot get by with a simple account but genuinely require the proxy.Comment #27
dries commentedWould love to hear other people's thoughts on znerol's feedback.
@znerol: do you think this needs to be resolved in this patch or is this something that could be done in a follow-up?
Comment #28
xjmReroll for #2247991: [May 27] Move all module code from …/lib/Drupal/… to …/src/… for PSR-4.
Comment #29
effulgentsia commentedI agree with #22 regarding TestBase, and with #26 regarding the specific test changes as out of scope for this issue unless there's a reason they're needed.
Comment #30
znerol commentedRegarding the hunk in
TestBase, see #2275965: Remove all services from the TestBase container.Comment #31
damiankloip commentedIf you are mocking the container you should mock the services that would actually be in the container. If you are unit testing and just passing parameters into a constructor, use whatever you like to satisfy the interface.
But as mentioned in irc before, if zenerol feels that strongly about these few tests, do whatever gets it in. This was meant to be a quick issue tbh.
Comment #32
znerol commentedComment #33
damiankloip commented@znerol, so if we revert those parts, this is good in your opinion now?
Comment #34
znerol commentedI prefer getting in #2196241: Remove string translation services from TestBase container which will remove all services from
TestBase. I do not see a benefit in changingFormCacheTestandStorageTestBasebecause of the reasons stated in #26.Comment #35
damiankloip commentedComment #36
mgifford@znerol it's fixed now.
Comment #37
almaudoh commentedReroll. Nothing much left in it. Related: #287292: Add functionality to impersonate a user
Comment #38
znerol commentedOh, indeed. In my point of view #37 should be incorporated into #287292: Add functionality to impersonate a user or in a followup thereof.
Comment #39
znerol commentedComment #40
mgiffordLet's try this again. A very simple re-roll.
Comment #41
damiankloip commentedYep, looks like this is the only usage now that is not in a unit test.
Comment #43
mitrpaka commentedRe-roll once again.
Comment #44
dawehnerUsed to be RTBC already.
Comment #45
webchickOk, I believe znerol's feedback has been incorporated via other issues, so this should be safe to commit. Also, this seems like just a code clean-up, so no need for it to be major. It does make the code more robust, however, by switching to the user switching API, so seems legit as far as https://www.drupal.org/contribute/core/beta-changes goes.
Committed and pushed to 8.0.x. Thanks!
Comment #47
webchickOops. Based on dawehner's feedback in IRC, this should actually be using the new account_switcher service instead.
Rolled back for now. Should be an easy-ish fix tho.
Comment #49
mitrpaka commentedUpdated patch with account_switcher service.
Comment #52
dawehner+1
Comment #53
almaudoh commentedIt's always a good idea to end calls to
::switchTo()with a corresponding::switchBack()after the code block that was executed as another user. Though that would not affect this test, because the entire container is rebuilt anyway for the next test, it's good to demonstrate good coding practice in core.Comment #54
webchickThat sounds like a needs work.
Comment #55
mitrpaka commentedPatch updated based on #53. Thanks.
Comment #56
dawehnerFair
Comment #57
webchickGreat, thanks.
Committed and pushed to 8.0.x (for real this time :)). Thanks!