mehr-als-nix / json-faker
Create fake JSON with fzaninotto/Faker
Installs: 29 274
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: >=7.3
- fzaninotto/faker: ^1.9
Requires (Dev)
- phpunit/phpunit: ^9.2
This package is auto-updated.
Last update: 2024-09-20 20:05:53 UTC
README
Creates JSON fixtures with fzaninotto/Faker
Installation
Add mehr-als-nix/json-faker
dependency to the require
section inside your composer.json
"require": { "mehr-als-nix/json-faker": "*" }
Examples
<?php use MehrAlsNix\JsonFaker\JsonFaker; $jsonTemplate = <<<JSON { "options": [ { "__JSON_OPTIONS__": "JSON_PRETTY_PRINT|JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP|JSON_UNESCAPED_SLASHES", "__NODE_CLONE__": 3 } ], "fixture": [ { "float-value": "__RAND_FLOAT__", "boolean-value": "__RAND_BOOLEAN__", "number-value": "__RAND_NUMBER__", "simple-text": "__RAND_TEXT__", "user-agent": "__RAND_USERAGENT__" } ] } JSON; echo (string) new JsonFaker($jsonTemplate, false);
Running this script generates a JSON string with random values like:
[ { "float-value": 157176.955378, "boolean-value": true, "number-value": 855701, "simple-text": "pariatur ad", "user-agent": "Opera/8.99 (Windows NT 6.2; sl-SI) Presto/2.9.218 Version/12.00" }, { "float-value": 1, "boolean-value": true, "number-value": 1207, "simple-text": "ex sit", "user-agent": "Mozilla/5.0 (iPad; CPU OS 7_1_1 like Mac OS X; sl-SI) AppleWebKit/535.11.1 (KHTML, like Gecko) Version/4.0.5 Mobile/8B118 Safari/6535.11.1" }, { "float-value": 933, "boolean-value": true, "number-value": 59201435, "simple-text": "voluptatem qui", "user-agent": "Mozilla/5.0 (iPad; CPU OS 8_1_2 like Mac OS X; en-US) AppleWebKit/532.46.4 (KHTML, like Gecko) Version/4.0.5 Mobile/8B116 Safari/6532.46.4" } ]