Skip to content

Commit 95d2a96

Browse files
authored
fix: autorefresh should work after kernel shutdown (#1011)
1 parent aba4841 commit 95d2a96

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/Configuration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ public static function isBooted(): bool
130130
/** @param \Closure():self|self $configuration */
131131
public static function boot(\Closure|self $configuration): void
132132
{
133-
PersistedObjectsTracker::reset();
134133
self::$instance = $configuration;
135134
}
136135

tests/Fixture/App/Controller/UpdateGenericModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
final class UpdateGenericModel
2424
{
2525
#[Route('/orm/update/{id}/{newValue}')]
26-
public function ormDelete(EntityManagerInterface $entityManager, int $id, string $newValue = 'foo'): Response
26+
public function ormUpdate(EntityManagerInterface $entityManager, int $id, string $newValue = 'foo'): Response
2727
{
2828
$genericEntity = $entityManager->find(GenericEntity::class, $id);
2929
$genericEntity?->setProp1($newValue);
@@ -33,7 +33,7 @@ public function ormDelete(EntityManagerInterface $entityManager, int $id, string
3333
}
3434

3535
#[Route('/mongo/update/{id}/{newValue}')]
36-
public function mongoDelete(DocumentManager $entityManager, int $id, string $newValue = 'foo'): Response
36+
public function mongoUpdate(DocumentManager $entityManager, int $id, string $newValue = 'foo'): Response
3737
{
3838
$genericDocument = $entityManager->find(GenericDocument::class, $id);
3939
$genericDocument?->setProp1($newValue);

tests/Integration/Persistence/AutoRefreshTestCase.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function it_can_refresh_after_update_with_browser(): void
116116
}
117117

118118
#[Test]
119-
public function it_can_refresh_twice_after_update_with_browser(): void
119+
public function it_can_refresh_twice_using_http_client(): void
120120
{
121121
$client = self::createClient();
122122

@@ -133,12 +133,26 @@ public function it_can_refresh_twice_after_update_with_browser(): void
133133
}
134134

135135
#[Test]
136-
#[Depends('it_can_refresh_after_update_with_browser')]
136+
#[Depends('it_can_refresh_twice_using_http_client')]
137137
public function tracker_is_empty_after_test(): void
138138
{
139139
self::assertSame(0, PersistedObjectsTracker::countObjects());
140140
}
141141

142+
#[Test]
143+
public function it_can_refresh_the_objects_after_kernel_shutdown(): void
144+
{
145+
$object = $this->factory()->create();
146+
self::assertSame('default1', $object->getProp1());
147+
148+
self::ensureKernelShutdown();
149+
$client = self::createClient();
150+
151+
$client->request('GET', "/{$this->dbms()}/update/{$object->id}/foo");
152+
self::assertResponseIsSuccessful();
153+
self::assertSame('foo', $object->getProp1());
154+
}
155+
142156
#[Test]
143157
#[TestWith(['deleteDirectlyInDb' => false, 'clearOM' => true])]
144158
#[TestWith(['deleteDirectlyInDb' => false, 'clearOM' => false])]
@@ -281,7 +295,7 @@ public static function provideRepositoryMethod(): iterable
281295
}
282296

283297
#[Test]
284-
public function it_can_refresh_object_fetched_find_and_id(): void
298+
public function it_can_refresh_object_fetched_using_find_and_an_id(): void
285299
{
286300
$id = $this->factory()->create()->id;
287301

@@ -290,7 +304,7 @@ public function it_can_refresh_object_fetched_find_and_id(): void
290304
PersistedObjectsTracker::reset();
291305

292306
self::assertNull(
293-
$this->factory()::repository()->find(43)
307+
$this->factory()::repository()->find(99999)
294308
);
295309

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

0 commit comments

Comments
 (0)