Skip to content

faker seed is not applied after kernel shutdown #1055

@verfriemelt-dot-org

Description

@verfriemelt-dot-org

hi,

image a symfony kernel testcase like this:

class FakerTest extends ApplicationWebTestCase {
    public function test(): void {
//        $this->client->request('get','/');
        static::assertSame('dolore', faker()->word());
    }
    public function test2(): void {
        static::assertSame('distinctio', faker()->word());
    }

    public function test3(): void {
        // 924691
        static::assertSame('dolore', faker()->word());
    }
    public function test4(): void {
        // 924691
        static::assertSame('distinctio', faker()->word());
    }
}

(the kerneltestcase has use Factories;, nothing to fancy in the shutdown, kernel gets rebootet with every test)

running this via

$ FOUNDRY_FAKER_SEED=924691 phpunit --testsuite Application --filter Faker
[...]
..FF                                                                4 / 4 (100%)

Faker seed: 924691

Time: 00:00.071, Memory: 28.00 MB

There were 2 failures:

1) FakerTest::test3
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'dolore'
+'odit'

FakerTest.php:17

2) FakerTest::test4
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'distinctio'
+'vitae'

i get what i expect, the "errors" stay the same, because the seed is actually used. if i now run the request $this->client->request('get','/'); , those values will not stay the same anymore,

i would expect to be stable, but with every run of the tests there will be different outcomes 🤔

Current configuration for extension with alias "zenstruck_foundry"
==================================================================

zenstruck_foundry:
    persistence:
        flush_once: true
    enable_auto_refresh_with_lazy_objects: true
    auto_refresh_proxies: null
    faker:
        locale: null
        seed: null
        service: null
    instantiator:
        use_constructor: true
        allow_extra_attributes: false
        always_force_properties: false
        service: null
    global_state: {  }
    orm:
        auto_persist: true
        reset:
            connections:
                - default
            entity_managers:
                - default
            mode: !php/enum Zenstruck\Foundry\ORM\ResetDatabase\ResetDatabaseMode::SCHEMA
            migrations:
                configurations: {  }
    mongo:
        auto_persist: true
        reset:
            document_managers:
                - default
    make_factory:
        default_namespace: Factory
        add_hints: true
    make_story:
        default_namespace: Story

this is symfony8, php8.5, latest foundry version

any suggestions where to look for to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions