Skip to content

A PHP faker provider to generate fake news headlines, suitable for testing news based content, or just making general dummy text more fun than lorem ipsum.

License

Notifications You must be signed in to change notification settings

paulhennell/faker-news

Repository files navigation

A fake news provider for php Faker

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.

About

A PHP faker provider to generate fake news headlines, suitable for testing news based content, or just making general dummy text more fun than lorem ipsum.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages