Problem/Motivation
In #3353658: [PHPUnit 10] Provide a static alternative to randomMachineName() and implement in data providers, we introduced new static methods for random data generation in tests.
In this issue, we explore whether deprecating the non-static methods, contained in RandomGeneratorTrait, for later removal.
Comments
Comment #2
spokjeAt first glance, this might become a META where we deprecate methods one by one, since especially
$this->randomMachineName()is used a _lot_, but let's see where we end up if we go all in.Comment #3
mondrakeTo be honest, I'm not even sure this is worth doing. Having a trait in the base classes and calling the methods non-statically allows avoiding the
useimport.Comment #4
spokjeHmm, that makes sense, we're looking at ~2500 lines of changed code here.
Maybe we do a nice "Closed (won't fix)" and move on to bigger (or rather smaller in code lines) and better things?
Comment #5
mondrakeMaybe we could limit to deprecating the use of the magic
__gets introduced by the parent (i.e. stop allowing accessing the property directly) and maybeRandomGeneratorTrait::randomStringValidate()which is just a callback that is no longer called since the entire implementation moved to the new static methods.Comment #6
catchThe
__getwas the one from the original issue that I thought we might not want to keep around forever.$this->randomMachineName() seems like it might be more trouble than it's worth to get rid of.
Comment #7
spokjeThere are also
\Drupal\Tests\UnitTestCase::randomMachineNameand\Drupal\Tests\UnitTestCase::getRandomGeneratorthat are now basically copies of the methods in the Trait.Do we want/need to do anything with those?
Comment #8
mondrakeMaybe in UnitTestCase we could use the trait and remove the direct implementations?
Comment #9
spokjeOpened #3358375: Fix incorrect usage of randomStringValidate in \Drupal\Tests\jsonapi\Kernel\Normalizer\JsonApiDocumentTopLevelNormalizerTest::setUp about some weird/incorrect usage of
RandomGeneratorTrait::randomStringValidate()Comment #10
spokjeComment #11
spokjeTurned this issue into a META to prevent child-issues from delaying up each other from being committed.
Comment #13
mondrake@spokje I think this can be closed now?
Comment #14
spokje@mondrake Agreed, thanks!