Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

VGirol/JsonApi-Faker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JsonApi-Faker

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Infection MSI Total Downloads

This package provides a set of factories to build fake data using the JSON:API specification.

Technologies

  • PHP 7.3+

Installation

To install through composer, simply put the following in your composer.json file:

{
    "require-dev": {
        "vgirol/jsonapi-faker": "dev-master"
    }
}

And then run composer install from the terminal.

Quick Installation

Above installation can also be simplified by using the following command:

composer require vgirol/jsonapi-faker

Usage

First create a faker generator.

use VGirol\JsonApiFaker\Generator as JsonApiFaker;

$faker = new JsonApiFaker;

Then create a factory.

$factory = $faker->resourceObject();

Next you can fill the factory ...

$factory->setResourceType('test')
        ->setId('1')
        ->setAttributes([
            'attr1' => 'value1',
            'attr2' => 'value2'
        ])
        ->setMeta([
            'key1' => 'meta1'
        ])
        ->addLink('self', 'url');

... or generate a fake.

$factory->fake();

Finally export as an array or as JSON.

$array = $factory->toArray();
$json = $factory->toJson();

All these instructions can be chained.

use VGirol\JsonApiFaker\Generator as JsonApiFaker;

$json = new JsonApiFaker()
    ->resourceObject()
    ->fake()
    ->toJson();

Documentation

The API documentation is available in XHTML format at the url http://jsonapi-faker.girol.fr/docs/ref/index.html.

Change log

Please see CHANGELOG for more information on what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published