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 07:03 UTC
Updated:
26 Apr 2020 at 14:14 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
mondrakeThere's only one test using this method. However, fixing is non-trivial since this method is checking a protected propeorty. In PHPUnit philosophy, this shouldn't be the case. However, there's no public API to get the content of the property being tested, and the only alternative weapon would be to use Reflection.
So it's better pause one moment and address the philosophical question first: shall we extend the API or use Reflection?
Comment #4
mondrakeA patch for the API way.
Comment #5
longwaveI think we can just simplify the test here.
Comment #7
daffie commentedThis line is not testing the protected class variable $translations is empty.
Also adding code to the class
Drupal\locale\LocaleTranslation, so that we can better test it is to me wrong solution. Do as @mondrake suggested in comment #2, use Reflection. That is what it is for.Comment #8
longwaveBut does it need to actually test that? That is an implementation detail. The test was originally added to ensure that destroying the object doesn't cause a crash, which is proved by the failing patch I posted (which reverts what was done when the test was first added)
Comment #9
mondrake#7, #8 that's the philosophical question...
See https://github.com/sebastianbergmann/phpunit/issues/3339
Maybe PHPUnit was too strict in dropping this so fast, but it's more to us now if we want to follow suit with this directionally, or not. Using Reflection is exactly a bypass into implementation details - however sometimes that may be the only option, as some comments on the post indicate (accessing factories, for example).
However, for the issue at hand here that assertion seems superfluous, so I think it's OK to just remove it. An alternative if we do not want to add API would be to throw an Exception if the value of ::$translations is null instead of empty array and capture that with a
expectExceptionin the test.Comment #10
alexpottCommitted and pushed 0bfda930ab to 9.1.x and b107631272 to 9.0.x. Thanks!
I agree that we shouldn't test internals. We're testing the original error - so that's great.