Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Persistence/PersistenceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ private function flushAllStrategies(): void
$this->flush($om);
}
}
PersistedObjectsTracker::updateIds();
Copy link
Member

@nikophil nikophil Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juste for you to know, in a further PR, we plan to remove this method, in favor of future so-called "foundry hooks"

see #986

I think it will work out of the box then. But we're not ready to merge it, so let's release your fix now 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the info.

}

/**
Expand Down
19 changes: 18 additions & 1 deletion tests/Integration/Persistence/AutoRefreshTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use function Zenstruck\Foundry\factory;
use function Zenstruck\Foundry\Persistence\assert_not_persisted;
use function Zenstruck\Foundry\Persistence\assert_persisted;
use function Zenstruck\Foundry\Persistence\flush_after;
use function Zenstruck\Foundry\Persistence\refresh;
use function Zenstruck\Foundry\Persistence\refresh_all;

Expand Down Expand Up @@ -223,6 +224,22 @@ public function it_can_refresh_all_objects(): void
self::assertSame('foo', $object2->getProp1());
}

#[Test]
public function it_can_refresh_all_objects_in_flush_after(): void
{
[$object1, $object2] = flush_after(fn() => $this->factory()->many(2)->create());
$objectId1 = $object1->id;
$objectId2 = $object2->id;

refresh_all();

$this->updateObject($objectId1);
$this->updateObject($objectId2);

self::assertSame('foo', $object1->getProp1());
self::assertSame('foo', $object2->getProp1());
}

#[Test]
#[DataProvider('provideRepositoryMethod')]
public function it_can_refresh_objects_fetched_from_repository_decorator(string $methodName, array $params): void
Expand Down Expand Up @@ -273,7 +290,7 @@ public function it_can_refresh_object_fetched_find_and_id(): void
PersistedObjectsTracker::reset();

self::assertNull(
$this->factory()::repository()->find(42)
$this->factory()::repository()->find(43)
);

$object = $this->factory()::repository()->find($id);
Expand Down