Skip to content

Creating a faker instance via Factroy::create shares a state with other instances #1002

@michiruf

Description

@michiruf

Summary

I've run into issues assuming a faker instance created via the factory is isolated from other faker instances.

Versions

Version
PHP 8.4.12
fakerphp/faker 1.24.1

Self-enclosed code snippet for reproduction

use Faker\Factory;

test('faker should return the same uuid on different instances', function () {
    $f1 = Factory::create();
    $f1->seed(0);

    $f2 = Factory::create();
    $f2->seed(0);

    expect($f1->uuid())->toBe($f2->uuid());
});

Expected output

Test passed

Actual output

Failed asserting that two strings are identical.
Expected :'46d87f7a-fb2f-35f9-a552-02133b0464df'
Actual   :'e72d9fb1-c496-3ce0-bdb5-cb77f63adfb4'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions