Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions system/Database/Seeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class Seeder
* Faker Generator instance.
*
* @var Generator|null
*
* @deprecated
*/
private static $faker;

Expand Down Expand Up @@ -98,6 +100,8 @@ public function __construct(Database $config, ?BaseConnection $db = null)

/**
* Gets the Faker Generator instance.
*
* @deprecated
*/
public static function faker(): ?Generator
{
Expand Down
3 changes: 3 additions & 0 deletions tests/system/Database/DatabaseSeederTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function testInstantiateNotDirSeedPath()
new Seeder($config);
}

/**
* @TODO remove this when Seeder::faker() is removed
*/
public function testFakerGet()
{
$this->assertInstanceOf(Generator::class, Seeder::faker());
Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.1.6.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Changes
Deprecations
************

- ``Seeder::faker()`` and ``Seeder::$faker`` are deprecated.

Sending Cookies
===============

Expand Down
35 changes: 0 additions & 35 deletions user_guide_src/source/dbmgmt/seeds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,6 @@ anywhere the autoloader can find them. This is great for more modular code bases
$this->call('My\Database\Seeds\CountrySeeder');
}

Using Faker
===========

If you want to automate the generation of seed data, you can use
the `Faker library <https://github.com/fakerphp/faker>`_.

To install Faker into your project::

> composer require --dev fakerphp/faker

After installation, an instance of ``Faker\Generator`` is available in the main ``Seeder``
class and is accessible by all child seeders. You must use the static method ``faker()``
to access the instance.

::

<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

class UserSeeder extends Seeder
{
public function run()
{
$model = model('UserModel');

$model->insert([
'email' => static::faker()->email,
'ip_address' => static::faker()->ipv4,
]);
}
}

Using Seeders
=============

Expand Down