Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.3.2] new()->many(2) creates single instance #811

Closed
xdrew opened this issue Feb 10, 2025 · 3 comments
Closed

[2.3.2] new()->many(2) creates single instance #811

xdrew opened this issue Feb 10, 2025 · 3 comments

Comments

@xdrew
Copy link

xdrew commented Feb 10, 2025

Hi! After an update from 2.3.1 some my tests began failing. The factory looks like:

final class OrderFactory extends PersistentProxyObjectFactory
{
    public function withProducts($count = 1): self
    {
        return $this->with(['orderProducts' => OrderProductFactory::new()->many($count)]);
    }
}

And calling this code:

        $user = UserFactory::createOne();
        $order = OrderFactory::new()->withUser($user)->withProducts(2)->create();

        $json = $this
            ->browser()
            ->actingAs($user->_real())
            ->get('/api/orders/' . $order->getUuid())
            ->assertStatus(200)
            ->dump()
            ->json();

shows:

...
{
    "orderProducts": [
        {
            "id": 129,
        }
    ],

On 2.3.1 it creates and shows 2. The bug also appears for 2.3.3 version

@nikophil nikophil added bug Something isn't working and removed bug Something isn't working labels Feb 10, 2025
@nikophil
Copy link
Member

Hello @xdrew

I cannot reproduce your problem.

Could you create a reproducer, or create a failing test case in Foundry's testsuite? You'll find a OneToMany in Category::$contact. You can add the test in EntityFactoryRelationshipTestCase

@xdrew
Copy link
Author

xdrew commented Feb 10, 2025

Could you create a reproducer, or create a failing test case in Foundry's testsuite? You'll find a OneToMany in Category::$contact. You can add the test in EntityFactoryRelationshipTestCase

Ok, I'll take a look

@nikophil
Copy link
Member

I'm closing this, since I was unable to reproduce, and the case is covered by tests:

public function one_to_many_with_factory_collection(): void

feel free to reopen it, with a reproducer project (or a failing test case in the tests)

@nikophil nikophil closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants