Closed (fixed)
Project:
Drupal core
Version:
8.3.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Sep 2016 at 08:46 UTC
Updated:
6 Oct 2016 at 14:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
dawehnerComment #3
martin107 commentedLooking at AssertPageCacheContextsAndTagsTrait for other similar problems
The use of $this->assertIdentical() needs to be removed from assertCacheTags() also
Comment #4
martin107 commentedLess unintended coupling - that is a good idea.
I need to signal a slight change is behaviour
previously if assertCacheContext were called with a NULL message then a default message would be constructed inside assertIdentical.
to see this message post patch, we have to rely on the debug function call to see that information. - but that follows the convention setup in the rest of the trait.
Comment #5
dawehnerYeah we don't need to change this one.
Is there a reason why you don't use $this->assert()? assert() is something else.
Comment #6
martin107 commentedbelatedly, I agree with #5.
Conventionally methods of the form assertXYZ() don't return a bool
So the next step is to just to assert and not return a boolean.
This has consequences for code that used to make use of the bool.
ToolbarCacheContextsTest::assertToolbarCacheContexts()
Thankfully the chain ends there and nothing uses the return value from assertToolbarCacheContexts()
I have preserved the message - daisy chaining but since there are two assert in assertToolbarCacheContexts the (human) debugger needs to know which point failed.
so I have added a suffix to the message if it is passed in.
-- Did I go too far?
Comment #8
dawehnerIMHO we don't really have to adapt toolbar test. When we return FALSE in WTB land, we would directly throw the exception in BTB land and no longer have to care about anything. Given that we can always assume that those return TRUE basically.
Do you understand what I mean with that?
Comment #9
martin107 commentedRegarding toolbar tests.... as you wish.
In the next patch I have inserted a Variable name change:- $return becomes $match.
We are actively using it in the method, and I would rather the name have semantic value, and then also happen to be the variable we return.
In relation to #5
It is a matter of coupling... looking inside the original call the assertIdentical() - it made use of asser().... Ahem I was just copying
.
$this->assert() implies extending WebAssert, the errors I created in #6 stem from this.
For example look at this stirng of classes
CommentRssTest -- CommentTestBase -- Drupal\simpletest\WebTestBase
At the moment this version of WebTestBase in the string does not pick up webAssert so no assert() and the test fail with a fatal.
In your little unofficial initiative - will this be resolved by other issues?
I'm sorry my knowledge is not wide enough to answer this question.
For the moment I am going to leave the assert() in and post a patch, and say I will be happy to adjust, accordingly.
Maybe we should postpone until other issues resolve the problem?
Comment #10
dawehnerAh I see what you mean. What about the following:
a) Keep your code with the debug() call
b) Keep the assertion:
c) When
$return === NULL(which is the BTB case), return TRUE.With that we should have a working version in both BTB and WTB.
What do you think about that?
Comment #11
martin107 commentedThat works - I am adding documentation - because the next coder along may be confused initially.
Also I want to be careful to "get the cart before the horse" [ I seem to remember there is a similar idiom in german :) ]
In short we have to make the comparison twice - because under failure conditions we have a call to assert in assertIdentical() and I want the debug to show first.
Comment #12
dawehnerThere indeed is.
Nice work!
Comment #13
klausicomments should wrap at 80 characters. Also the comment is wrong, we don't always return a boolean.
Should be "For compatibility with both BrowserTestBase and WebTestBase only return a boolean for WebTestBase."
Which also means we need to adapt the @return docs of this method, right?
Which sounds overly complicated. I think it is fine to always return a boolean, nobody using BrowserTestBase will care.
Comment #14
dawehnerSo you argue to not return a boolean for BTB? I thought we keep the existing behaviour and always return a boolean, also for BTB and call it a day.
Comment #15
klausiYes, always return a boolean and not do this complicated NULL handling in the current patch.
Comment #16
dawehnerWell, how would you do that? The BTB version of
assertIdenticalreturns NULL. The WTB version returns a boolean, we actually want to return.Comment #17
klausiWe can just return the $return variable that is explicitly being prepared in the patch.
Comment #18
martin107 commentedI don't follow your logic.
if the output of assertIdentical() in some configurations returns null - and the value is used to create $return
how is this compatible with "yes, always return a boolean" ( #15)
Comment #19
klausiSorry, I meant just return the $match variable like this.
Comment #20
tstoecklerThat's a pretty clear bug, no?
It's very important that assert*() methods return booleans. It's not done very much in core sadly, but good (TM) tests generally fail gracefully, which assert*() methods make very easy if they return booleans.
The following test code, for example, may fail, but it will never fatal:
Whereas if you can't/don't rely on the return value of assert*() and just do
your test will still never pass incorrectly, but it may fatal which is annoying from a CI/test runner/test logs perspective.
X-Post with @klausi: I think the last patch is a lot more elegant than previous versions, but should I open a separate ticket for the above?
Comment #21
martin107 commentedAh --- that makes the code simpler.
Klausi++
Comment #22
klausiWith the move to phpunit we are going to remove return values of assert*() methods to be consistent with phpunit core which never returns anything on assertions.
Fatal errors are fine, since phpunit as a testrunnner can properly deal with them.
The big difference in phpunit is that assertions throw exceptions when they fail. Which means as soon as one assertion fails the test case is finished and will not be continued.
Comment #23
dawehnerklausi++
Comment #24
dawehnerComment #25
tstoecklerAhh, yes had totally forgotten that point about PHPUnit, you're right. So my point above is moot. That has always bugged me a lot about PHPUnit, but whatever...
RTBC++
Comment #26
alexpottSince this is a test only change - and also makes no functional change - I think this is RC eligible.
Committed and pushed 52f2a29 to 8.3.x and 7ff6bb5 to 8.2.x. Thanks!