diff --git a/tests/Benchmark/LoadEventsBench.php b/tests/Benchmark/LoadEventsBench.php index 5b45a3c5d..6d074761f 100644 --- a/tests/Benchmark/LoadEventsBench.php +++ b/tests/Benchmark/LoadEventsBench.php @@ -10,6 +10,7 @@ use Patchlevel\EventSourcing\EventBus\EventBus; use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; +use Patchlevel\EventSourcing\Repository\Repository; use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager; use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer; use Patchlevel\EventSourcing\Store\SingleTableStore; @@ -28,6 +29,7 @@ final class LoadEventsBench private Store $store; private EventBus $bus; + private Repository $repository; public function setUp(): void { @@ -49,7 +51,7 @@ public function setUp(): void 'eventstore' ); - $repository = new DefaultRepository($this->store, $this->bus, Profile::class); + $this->repository = new DefaultRepository($this->store, $this->bus, Profile::class); // create tables (new DoctrineSchemaManager())->create($this->store); @@ -60,15 +62,13 @@ public function setUp(): void $profile->changeName('Peter'); } - $repository->save($profile); + $this->repository->save($profile); } #[Bench\Revs(10)] #[Bench\Iterations(2)] public function benchLoadEvents(): void { - $repository = new DefaultRepository($this->store, $this->bus, Profile::class); - - $repository->load('1'); + $this->repository->load('1'); } } diff --git a/tests/Benchmark/LoadEventsWithSnapshotsBench.php b/tests/Benchmark/LoadEventsWithSnapshotsBench.php index 5893f5ba3..244cbca49 100644 --- a/tests/Benchmark/LoadEventsWithSnapshotsBench.php +++ b/tests/Benchmark/LoadEventsWithSnapshotsBench.php @@ -10,6 +10,7 @@ use Patchlevel\EventSourcing\EventBus\EventBus; use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory; use Patchlevel\EventSourcing\Repository\DefaultRepository; +use Patchlevel\EventSourcing\Repository\Repository; use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager; use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer; use Patchlevel\EventSourcing\Snapshot\Adapter\InMemorySnapshotAdapter; @@ -32,6 +33,7 @@ final class LoadEventsWithSnapshotsBench private Store $store; private EventBus $bus; private SnapshotStore $snapshotStore; + private Repository $repository; public function setUp(): void { @@ -55,7 +57,7 @@ public function setUp(): void $this->snapshotStore = new DefaultSnapshotStore(['default' => new InMemorySnapshotAdapter()]); - $repository = new DefaultRepository($this->store, $this->bus, Profile::class, $this->snapshotStore); + $this->repository = new DefaultRepository($this->store, $this->bus, Profile::class, $this->snapshotStore); // create tables (new DoctrineSchemaManager())->create($this->store); @@ -66,7 +68,7 @@ public function setUp(): void $profile->changeName('Peter'); } - $repository->save($profile); + $this->repository->save($profile); $this->snapshotStore->save($profile); } @@ -74,8 +76,6 @@ public function setUp(): void #[Bench\Iterations(2)] public function benchLoadEvents(): void { - $repository = new DefaultRepository($this->store, $this->bus, Profile::class, $this->snapshotStore); - - $repository->load('1'); + $this->repository->load('1'); } }