-
-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Provide an interface for the random string generator #3
Conversation
Sorry for the delayed response. The reason there isn't an interface here already is that the random generator has been plucked directly from Drupal 8 (I was hoping the components there would eventually be available individually via Ideally, I'd like to see Drupal 8 adopt an interface approach, but in the meantime, I think this approach makes sense to do here. Somebody on twitter mentioned using https://github.com/rchouinard/rych-random as a random generator, I wonder if that would be possible still with this approach? |
I have used rych-random in a previous project but we eventually abandoned it for a self rolled solution since it is rather basic. What is very nice about it is that it scans your system for available random number generators and will use the best available. We decided to abandon it because in testing it is very interesting to be able to retrieve valid data as well as invalid data, and also to be able to extend it so you can test things like URLs, email addresses etc. This is the interface we used, it served us pretty well (ref http://cgit.drupalcode.org/paddle_selenium_tests/tree/testdataprovider/Kanooh/TestDataProvider/TestDataProviderInterface.php?h=7.x-1.x):
This can be coupled with a base class that implements Here is the full set of classes: http://cgit.drupalcode.org/paddle_selenium_tests/tree/testdataprovider/Kanooh/TestDataProvider?h=7.x-1.x |
@@ -82,6 +83,7 @@ public function __construct($alias = NULL, $root_path = NULL, $binary = 'drush', | |||
|
|||
$this->binary = $binary; | |||
|
|||
// @todo This should not be optional but injected by a factory method. | |||
if (!isset($random)) { | |||
$random = new Random(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't actually work as written now, since Random
won't be available without a use
statement. I'd be happy to change this to using a factory method if you want to take a go at that.
I'd love to actually get an interface into Drupal core instead of just the Random class. |
If my feedback above in the DrushDriver is resolved, I'm open to making this change as-is, and we can always follow-up in core. |
We no longer directly hardcode the |
I've opened https://www.drupal.org/project/drupal/issues/2969060. Closing this out for now. |
The random string generator
\Drupal\Component\Utility\Random
is currently hardcoded in the project. It would be better if this conformed to an interface so it can be properly injected. This would allow us to override it, and it allow the methods to be autocompleted by IDEs.