zenstruck / foundry

A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.
https://symfony.com/bundles/ZenstruckFoundryBundle/current/index.html
MIT License
644 stars 70 forks source link

createMany and createOne or new->create does not work well together on the CI #482

Closed benblub closed 3 months ago

benblub commented 1 year ago
        EmbeddedContentFactory::createMany(5);
        EmbeddedContentFactory::createMany(3, ['type' => EmbeddedContentType::CantonNavigation]);
        EmbeddedContentFactory::createOne(['title' => 'Exact title', 'type' => EmbeddedContentType::Fixture]);

        $this->assertCount(9, EmbeddedContentFactory::repository()->findAll(), 'Expected 9 embedded contents');

This is failing in CI/Github actions = Failed asserting that actual size 8 matches expected size 9.

What is working

        EmbeddedContentFactory::createMany(
            6,
            static function (int $i) {
                if ($i === 1) {
                    return ['title' => 'Exact title', 'type' => EmbeddedContentType::Fixture];
                }

                return ['title' => "Title $i"];
            }
        );
        EmbeddedContentFactory::createMany(3, ['type' => EmbeddedContentType::CantonNavigation]);

        $this->assertCount(9, EmbeddedContentFactory::repository()->findAll(), 'Expected 9 embedded contents');

I trying to understand what the problem can be but since its working local its hard to debug. Did someone know or can lead me the right direction? Not sure this is a bug ..

Additional: DAMA is used, the code is failing early without other code involved.

benblub commented 1 year ago

fun fact

If I switch the order there is no error raised

        EmbeddedContentFactory::createOne(['title' => 'Exact title', 'type' => EmbeddedContentType::Fixture]);
        EmbeddedContentFactory::createMany(5);
        EmbeddedContentFactory::createMany(3, ['type' => EmbeddedContentType::CantonNavigation]);

        $this->assertCount(9, EmbeddedContentFactory::repository()->findAll(), 'Expected 9 embedded contents');
nikophil commented 1 year ago

Hi @benblub

sorry I have no clue why this is happening. I bet this is not related to Foundry, but not really sure. The "fun fact" is really weird :exploding_head:

Maybe if you can create a public reproducer I could give a hand.

I recently heard about https://github.com/mxschmitt/action-tmate which can help to debug your actions by ssh-ing on the runners, maybe this could help!

benblub commented 1 year ago

ok will take a look by time, thx

nikophil commented 3 months ago

I'm closing this stale issue. feel free to reopen :)