Closed (fixed)
Project:
Drupal core
Version:
9.0.x-dev
Component:
phpunit
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
10 Apr 2020 at 06:49 UTC
Updated:
2 May 2020 at 08:07 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mondrakeKickoff patch, unsilencing the deprecation to see size of the changes needed.
Comment #4
mondrakeSame as #3126563-2: Replace usage of assertAttributeEquals() that is deprecated, fixing this is not trivial, since this method is checking a protected property. In latest PHPUnit philosophy (see the rather blunt comments in https://github.com/sebastianbergmann/phpunit/issues/3338), this shouldn't be the case.
So either we use Reflection, or we refactor the runtime code to provide the info we need for the test.
Here, a proposal for the database ConnectionTest.
These issues related to
assertAttribute*removals are going to require lots of discussion...Comment #5
mondrakeComment #6
mondrakeComment #7
mondrakeTwo relatively simple ones to fix.
Comment #10
mondrakeSomething more. Sorry weird interdiff, includes other removals already committed.
Comment #11
mondrakeI suggest just to remove this, it practically just checks service injection, seems unnecessary
Comment #13
mondrakeHere again, it seems to me that testing the injection in the constructor is irrelevant
Comment #15
mondrakeRerolled and addressed remaining calls.
Comment #16
mondrakeComment #17
mondrake#15 inadvertendly reverted the change in #13.
Comment #18
daffie commentedThrowing a new exception must be documented in the docblock
Can we remove the line of code
$this->schema = NULL;. It is now not necessary any more.Why are we removing this piece of code in this issue?
Comment #19
mondrake@daffie re. #18
1. done
2. I do not think so, but one can try (theoretically) to access the schema on the destroyed connection, since it's on a public API. Once the connection is destructed, obviously, not.
3. Not really - the purpose is actually to null out the pointer to the schema object to allow garbage collection by PHP, so that's explicit.
4. Because it only seems to test the injection, which is superfluous IMO.
Comment #20
daffie commented@mondrake: Thank you for your explanation.
Can you move this line next to the line
$this->schema = NULL;and add some documentation why the schema must be set to NULL.Can we still keep testing with reflection that the variable $schema has the value NULL.
Comment #21
mondrake@daffie thanks
I think the method docblock of
destroyis detailed enough, already. Nonetheless I made some further additions. Re. using Reflection here, it would be useless at that point since you are expecting the exception and therefore the code execution path is interrupted. Also, the entire point of dropping that method, in PHPUnit philosophy, is to reduce use of Reflection for checking internals. However, I moved the exception throing to after a check that the schema was nulled, which IMO is better since it just tests the public surface.Comment #22
daffie commentedI want to keep the testing for
$this->schema = NULL, because it is important as you said: "the purpose is actually to null out the pointer to the schema object to allow garbage collection by PHP, so that's explicit".As we are not removing
$this->schema = NULL, the whole adding of the $destroyed parameter feels like it is out of scope for this issue. I like the functionality and that is why I am asking you to create a new issue for it.Comment #23
mondrake@daffie you only get the exception if the value of
$this->schemais null, so that's tested anyway. If we disagree, please let the issue in needs review so that someone else could comment, too.Comment #24
daffie commentedYes, we disagree and I shall leave the issue in needs review.
Comment #25
alexpottThe addition of the destroyed property needs way more work. Imo we need to evaluate the destroy method and move this code to __destruct() so the object is always destructed correctly. We need to look at #843114: DatabaseConnection::__construct() and DatabaseConnection_mysql::__construct() leaks $this (Too many connections) and work out why this solution was chosen.
I think using reflection here is preferable. And not changing runtime code for testability reasons.
+1 this test is not a test.
Comment #26
mondrakeOK. Let's revise
destroyseparately.Comment #27
alexpottOpened #3128616: Replace \Drupal\Core\Database\Connection::destroy() with a proper destructor to rid us of destroy().
Comment #28
mondrakeAddressed #20 and #25.
Comment #29
daffie commentedAll changes look good to me.
The suppression of warnings for the use of
assertAttributeEquals()is removed.All instances of
assertAttributeEquals()are removed.For me it is RTBC.
Comment #30
mondrakeI wonder whether we shoud use public methods instead of getters like in a previous similar case
Comment #31
alexpott@mondrake good idea - less boilerplate and it's all test code so getters have no value.
Comment #32
mondrakeComment #33
longwaveThe only changes are in tests or test implementations, the changes are as minimal as possible and follow what we did in recent similar issues, I think this is ready to go in.
Comment #34
alexpottCommitted and pushed a6e402fc01 to 9.1.x and 50a6075593 to 9.0.x. Thanks!
Comment #37
mondrakeThank you all for your reviews.