Skip to content

Commit bc2a356

Browse files
authored
Merge pull request #5490 from kenjis/deprecated-seeder-faker
docs: deprecate Seeder::faker()
2 parents 9bc6753 + b75b9af commit bc2a356

4 files changed

Lines changed: 9 additions & 35 deletions

File tree

system/Database/Seeder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class Seeder
6868
* Faker Generator instance.
6969
*
7070
* @var Generator|null
71+
*
72+
* @deprecated
7173
*/
7274
private static $faker;
7375

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

99101
/**
100102
* Gets the Faker Generator instance.
103+
*
104+
* @deprecated
101105
*/
102106
public static function faker(): ?Generator
103107
{

tests/system/Database/DatabaseSeederTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function testInstantiateNotDirSeedPath()
3838
new Seeder($config);
3939
}
4040

41+
/**
42+
* @TODO remove this when Seeder::faker() is removed
43+
*/
4144
public function testFakerGet()
4245
{
4346
$this->assertInstanceOf(Generator::class, Seeder::faker());

user_guide_src/source/changelogs/v4.1.6.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Changes
4242
Deprecations
4343
************
4444

45+
- ``Seeder::faker()`` and ``Seeder::$faker`` are deprecated.
46+
4547
Sending Cookies
4648
===============
4749

user_guide_src/source/dbmgmt/seeds.rst

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -67,41 +67,6 @@ anywhere the autoloader can find them. This is great for more modular code bases
6767
$this->call('My\Database\Seeds\CountrySeeder');
6868
}
6969

70-
Using Faker
71-
===========
72-
73-
If you want to automate the generation of seed data, you can use
74-
the `Faker library <https://github.com/fakerphp/faker>`_.
75-
76-
To install Faker into your project::
77-
78-
> composer require --dev fakerphp/faker
79-
80-
After installation, an instance of ``Faker\Generator`` is available in the main ``Seeder``
81-
class and is accessible by all child seeders. You must use the static method ``faker()``
82-
to access the instance.
83-
84-
::
85-
86-
<?php
87-
88-
namespace App\Database\Seeds;
89-
90-
use CodeIgniter\Database\Seeder;
91-
92-
class UserSeeder extends Seeder
93-
{
94-
public function run()
95-
{
96-
$model = model('UserModel');
97-
98-
$model->insert([
99-
'email' => static::faker()->email,
100-
'ip_address' => static::faker()->ipv4,
101-
]);
102-
}
103-
}
104-
10570
Using Seeders
10671
=============
10772

0 commit comments

Comments
 (0)