Download the PHP package marcoconsiglio/faker-php-number-helpers without Composer
On this page you can find all versions of the php package marcoconsiglio/faker-php-number-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download marcoconsiglio/faker-php-number-helpers
More information about marcoconsiglio/faker-php-number-helpers
Files in marcoconsiglio/faker-php-number-helpers
Package faker-php-number-helpers
Short Description Adds a helper trait that makes it easier to generate random numbers using FakerPHP.
License MIT
Informations about the package faker-php-number-helpers
faker-php-number-helpers
Adds a helper trait that makes it easier to generate random numbers using FakerPHP.
Index
- Installation
- Usage
- Available methods
- Integer generation
- Float generation
- Next
floatnumber - API Documentation
Installation
Use it as a production dependency
or a development dependency
Usage
Add the trait to a TestCase class if you use this library in your tests project written in PHPUnit, otherwise add it wherever you need it.
In some tests, you'll need a PHPUnit data provider, which is a static function. In this case you can call statically setUpFaker() method in order to set up a static Faker\Generator when PHPUnit call the data provider method, which is done prior to call the setUp() method.
Constants
Several constants provide the limit for random generation.
Integers
| Constant | Value |
|---|---|
IntRange::MIN |
PHP_INT_MIN + 1 |
IntRange::MAX |
PHP_INT_MAX |
Floats
| Constant | Value |
|---|---|
FloatRange::MIN |
-PHP_FLOAT_MAX |
FloatRange::MAX |
PHP_FLOAT_MAX |
FloatRange::MICRO |
PHP_FLOAT_MIN |
FloatRange::MAX_FRACTION |
4,503,599,627,370,495.0 |
FloatRange::MIN_FRACTION |
-4,503,599,627,370,495.0 |
Available methods
Integer generation
| Method | Minimum | Maximum | Excluded |
|---|---|---|---|
randomInteger() |
PHP_INT_MIN |
PHP_INT_MAX |
|
positiveRandomInteger() |
0 | PHP_INT_MAX |
|
negativeRandomInteger() |
PHP_INT_MIN + 1 |
-1 | 0 |
nonZeroRandomInteger() |
PHP_INT_MIN + 1 |
PHP_INT_MAX |
0 |
positiveNonZeroRandomInteger() |
1 | PHP_INT_MAX |
0 |
negativeNonZeroRandomInteger() |
PHP_INT_MIN + 1 |
-1 | 0 |
Float generation
| Method | Minimum | Maximum | Excluded |
|---|---|---|---|
randomFloat() |
-PHP_FLOAT_MAX |
PHP_FLOAT_MAX |
|
positiveRandomFloat() |
0 | PHP_FLOAT_MAX |
|
negativeRandomFloat() |
-PHP_FLOAT_MAX |
0 | 0 |
nonZeroRandomFloat() |
-PHP_FLOAT_MAX |
PHP_FLOAT_MAX |
0 |
positiveNonZeroRandomFloat() |
PHP_FLOAT_MIN |
PHP_FLOAT_MAX |
0 |
negativeNonZeroRandomFloat() |
-PHP_FLOAT_MAX |
-PHP_FLOAT_MIN |
0 |
randomFraction() |
FloatRange::MIN_FRACTION |
FloatRange::MAX_FRACTION |
integer floats |
positiveRandomFraction() |
PHP_FLOAT_MIN |
FloatRange::MAX_FRACTION |
integer floats |
negativeRandomFraction() |
FloatRange::MIN_FRACTION |
-PHP_FLOAT_MIN |
integer floats |
Next float number
Some times you need to have the previous/next representable float adjacent to a specific number.
To solve this problem you can use the NextFloat class, which is a convenient wrapper of the nsfisis/php-next-after library.
API Documentation
See more in the API Documentation at ./docs/html/index.html.