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: 0 additions & 1 deletion src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public static function isBooted(): bool
/** @param \Closure():self|self $configuration */
public static function boot(\Closure|self $configuration): void
{
PersistedObjectsTracker::reset();
Copy link
Member Author

Choose a reason for hiding this comment

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

culprit was here

Choose a reason for hiding this comment

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

Hello !
Looks like this change has side effect :

class FooTest extends WebTestCase
{
    use Factories;

    public function testFoo(): void
    {
        FooFactory::create();
    }
}

gives us

Error: Typed static property Zenstruck\Foundry\Persistence\Proxy\PersistedObjectsTracker::$buffer must not be accessed before initialization
/var/www/project/vendor/zenstruck/foundry/src/Persistence/Proxy/PersistedObjectsTracker.php:53
/var/www/project/vendor/zenstruck/foundry/src/Persistence/PersistenceManager.php:89
/var/www/project/vendor/zenstruck/foundry/src/Persistence/PersistentObjectFactory.php:266
/var/www/project/tests/Functional/FooTest.php:7

Is there anything special to do to initialize foundry with this new version ?

self::$instance = $configuration;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Fixture/App/Controller/UpdateGenericModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
final class UpdateGenericModel
{
#[Route('/orm/update/{id}/{newValue}')]
public function ormDelete(EntityManagerInterface $entityManager, int $id, string $newValue = 'foo'): Response
public function ormUpdate(EntityManagerInterface $entityManager, int $id, string $newValue = 'foo'): Response
{
$genericEntity = $entityManager->find(GenericEntity::class, $id);
$genericEntity?->setProp1($newValue);
Expand All @@ -33,7 +33,7 @@ public function ormDelete(EntityManagerInterface $entityManager, int $id, string
}

#[Route('/mongo/update/{id}/{newValue}')]
public function mongoDelete(DocumentManager $entityManager, int $id, string $newValue = 'foo'): Response
public function mongoUpdate(DocumentManager $entityManager, int $id, string $newValue = 'foo'): Response
{
$genericDocument = $entityManager->find(GenericDocument::class, $id);
$genericDocument?->setProp1($newValue);
Expand Down
22 changes: 18 additions & 4 deletions tests/Integration/Persistence/AutoRefreshTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function it_can_refresh_after_update_with_browser(): void
}

#[Test]
public function it_can_refresh_twice_after_update_with_browser(): void
public function it_can_refresh_twice_using_http_client(): void
{
$client = self::createClient();

Expand All @@ -133,12 +133,26 @@ public function it_can_refresh_twice_after_update_with_browser(): void
}

#[Test]
#[Depends('it_can_refresh_after_update_with_browser')]
#[Depends('it_can_refresh_twice_using_http_client')]
public function tracker_is_empty_after_test(): void
{
self::assertSame(0, PersistedObjectsTracker::countObjects());
}

#[Test]
public function it_can_refresh_the_objects_after_kernel_shutdown(): void
{
$object = $this->factory()->create();
self::assertSame('default1', $object->getProp1());

self::ensureKernelShutdown();
$client = self::createClient();

$client->request('GET', "/{$this->dbms()}/update/{$object->id}/foo");
self::assertResponseIsSuccessful();
self::assertSame('foo', $object->getProp1());
}

#[Test]
#[TestWith(['deleteDirectlyInDb' => false, 'clearOM' => true])]
#[TestWith(['deleteDirectlyInDb' => false, 'clearOM' => false])]
Expand Down Expand Up @@ -281,7 +295,7 @@ public static function provideRepositoryMethod(): iterable
}

#[Test]
public function it_can_refresh_object_fetched_find_and_id(): void
public function it_can_refresh_object_fetched_using_find_and_an_id(): void
{
$id = $this->factory()->create()->id;

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

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

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