https://github.com/valtzu/php-fakerandom
Mock random_bytes & random_int
https://github.com/valtzu/php-fakerandom
mocking php php-extension php8 random testing
Last synced: 5 months ago
JSON representation
Mock random_bytes & random_int
- Host: GitHub
- URL: https://github.com/valtzu/php-fakerandom
- Owner: valtzu
- Created: 2022-08-05T20:07:28.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-12-16T07:19:55.000Z (7 months ago)
- Last Synced: 2025-12-19T20:58:04.259Z (6 months ago)
- Topics: mocking, php, php-extension, php8, random, testing
- Language: C
- Homepage:
- Size: 18.6 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
fakerandom extension for PHP
============================
PHP extension that mocks `random_int` & `random_bytes` for testing purposes.
## Installation
### Docker
```dockerfile
FROM php:8.5
RUN curl -L https://github.com/valtzu/php-fakerandom/releases/download/v0.1.6/fakerandom_20250925.so > /usr/local/lib/php/extensions/no-debug-non-zts-20250925/fakerandom.so ;\
docker-php-ext-enable fakerandom
```
## Usage
### `random_int`
```php
fake_random_enable();
echo random_int(1, 3); // will be always 1 + (3 - 1) / 2 = 2
fake_random_disable();
echo random_int(1, 3); // original functionality restored
```
### `random_bytes`
```php
fake_random_enable();
echo bin2hex(random_bytes(3)); // will be always 010203 (goes up until "ff" and then "00" again)
fake_random_disable();
echo bin2hex(random_bytes(3)); // original functionality restored
```
## Build & test
```
docker-compose up --build
```