Hey Bruce

Thanks for the feedback!

On 26.09.22 09:00, Bruce Weirdan wrote:
On Mon, Sep 26, 2022 at 2:46 AM Andreas Heigl <andr...@heigl.org> wrote:

while we have by now
multiple Clock-implementations to ease testing with Dates and times
there is not really a way currently to ease testing with randomnes.

PHP itself provides the random_int and random_bytes functions and some
libraries provide additional sources of randomnes. But there is no way
of being able to "assert a certain random value" which makes functions
requiring randomness hard to test.

ANd so far I have not found any interoperability standard in that
direction in the PHP-Ecosystem. There are some libraries (not a huge
number) but I did not find an interface for interoperability and better
testing.

Isn't it already covered natively by https://wiki.php.net/rfc/rng_extension?
IMO Yes and No.

The rng_extension describes the Random\Engine interface. This interface has only the `generate` method which returns a string. The length of this string can not be specified.

In general the idea of the whole package was to "Create a single Randomizer class which provides various randomization methods (like get int/bytes, shuffle string/arrays). This class will take an Engine interface in the constructor which can be swapped based on users needs. Some essential RNG engines will be prepackaged for convenience but an Interface will also be provided so that algorithms can be easily added."

The main task here is to ease adding randomizers in the core later.

The task is only to a certain extend to allow interoperability (due to everyone using those methods) but sadly not to ease testing as the methods of the provided Randomizer class are not based on an interface.

So to be able to test this with fixed values you will have to depend on the Random\Randomizer-class and inject your own fixed Random\Engine implementation. There is no way to replace the Random\Randomizer with something else.

So if that is enough of interoperability, then I'm fine with that and there is no need for any further investigation.

Cheers

Andreas
--
                                                              ,,,
                                                             (o o)
+---------------------------------------------------------ooO-(_)-Ooo-+
| Andreas Heigl                                                       |
| mailto:andr...@heigl.org                  N 50°22'59.5" E 08°23'58" |
| https://andreas.heigl.org                                           |
+---------------------------------------------------------------------+
| https://hei.gl/appointmentwithandreas                               |
+---------------------------------------------------------------------+

--
You received this message because you are subscribed to the Google Groups "PHP 
Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to php-fig+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/php-fig/75549ae8-1770-2ab4-c6e1-51d9d2a012a9%40heigl.org.

Attachment: OpenPGP_0xA8D5437ECE724FE5.asc
Description: OpenPGP public key

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to