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] afterPersist not called for FactoryCollection for collection property with inversed relationship #821

Open
tandev opened this issue Feb 17, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@tandev
Copy link

tandev commented Feb 17, 2025

Since the update, it seems that afterPersist calls for an collection property with an inversed relationship are not called anymore

This can be reproduced by adding the following test cases to: \Zenstruck\Foundry\Tests\Integration\ORM\EntityRelationship\ProxyEntityFactoryRelationshipTest

    /** @test */
    public function it_uses_after_persist_with_collection(): void
    {
        $contact = static::contactFactory()->with(
            [
                'tags' => static::tagFactory()
                    ->afterPersist(function (Tag $tag) {$tag->setName('foobar');})
                    ->many(1)])
            ->create()
        ;

        self::assertEquals('foobar', $contact->getTags()->first()->getName());
    }

    /** @test */
    public function it_uses_after_persist_with_collection_with_inversed_relationship(): void
    {
        $contact = static::categoryFactory()
            ->with(
                [
                    'contacts' => static::contactFactory()
                        ->afterPersist(function (Contact $contact) {$contact->setName('foobar');})
                        ->many(1)])
            ->create()
        ;

        self::assertEquals('foobar', $contact->getContacts()->first()->getName());
    }
There was 1 failure:

1) Zenstruck\Foundry\Tests\Integration\ORM\EntityRelationship\ProxyEntityFactoryRelationshipTest::it_uses_after_persist_with_collection_with_inversed_relationship
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'foobar'
+'harum'

@nikophil
Copy link
Member

nikophil commented Feb 17, 2025

hi @tandev

yes, this problem makes sense. Thank you for these issues with failing test case, this is really helpful 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants