paulhennell/faker-news

Faker provider for fake news!

v2.0.0 2022-06-03 14:25 UTC

This package is auto-updated.

Last update: 2024-11-20 12:38:57 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

This is a custom provider for fakerphp/Faker generating fake news headlines for use when testing website design. Also includes a fake news source name generator.

Installation

You can install the package via composer:

composer require paulhennell/faker-news

Usage

$faker = (new \Faker\Factory())::create();
$faker->addProvider(new \Faker\Provider\Fakenews($faker));
$faker->addProvider(new \Faker\Provider\Fakenewssource($faker));

// generate a headline
echo $faker->headline;

// generate a named newssource (75% Newspapers, 25% TV news as below)
echo $faker->NewssourceName;

// generate a Newspaper name
// 'The Daily Texas', 'The Morning Herald', 'Manchester Post' etc
echo $faker->NewspaperName;

// generate a TV source name
// 'KKN News', 'ATV', 'JKK 247' etc
echo $faker->TvNewsName;

Laravel Factory Setup

Create a FakerService provider (and register in bootstrap/providers.php

class FakerServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(\Faker\Generator::class, function () {
            $faker = \Faker\Factory::create();
            $faker->addProvider(new Fakenews($faker));
            $faker->addProvider(new Fakenewssource($faker));
            return $faker;
        });
    }

You can now access the fields in the model factories:

'headline' => $this->faker->headline(),
'publisher' => $this->faker->NewssourceName(),

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

PHP Package Boilerplate

This package was generated using the PHP Package Boilerplate.