2323#[CoversClass(DoctrineBatchWriterTask::class)]
2424class DoctrineBatchWriterTaskTest extends TestCase
2525{
26- /**
27- * @param array $options
28- * @return DoctrineBatchWriterTask
29- */
3026 protected function getTask (array $ options = [], ?ManagerRegistry $ managerRegistry = null ): DoctrineBatchWriterTask
3127 {
32- if (!$ managerRegistry ) {
28+ if (!$ managerRegistry instanceof \ Doctrine \ Persistence \ManagerRegistry ) {
3329 $ managerRegistry = $ this ->createStub (ManagerRegistry::class);
3430 }
3531 $ task = new DoctrineBatchWriterTask ($ managerRegistry );
@@ -76,7 +72,6 @@ public function testExecuteFlushesBatchWhenBatchCountReached(): void
7672
7773 $ task = $ this ->getTask (['batch_count ' => 2 ], $ managerRegistry );
7874
79-
8075 // Simulate filling the batch
8176 $ reflection = new \ReflectionClass (DoctrineBatchWriterTask::class);
8277 $ batchProperty = $ reflection ->getProperty ('batch ' );
@@ -90,7 +85,6 @@ public function testExecuteFlushesBatchWhenBatchCountReached(): void
9085 $ this ->assertCount (0 , $ batchProperty ->getValue ($ task )); // Batch should be empty after flush
9186 }
9287
93-
9488 public function testFlushCallsWriteBatch (): void
9589 {
9690 $ state = $ this ->createStub (ProcessState::class);
@@ -144,7 +138,6 @@ public function testWriteBatchPersistsAndFlushesEntities(): void
144138
145139 // Call writeBatch directly
146140 $ writeBatchMethod = $ reflection ->getMethod ('writeBatch ' );
147- $ writeBatchMethod ->setAccessible (true );
148141 $ writeBatchMethod ->invoke ($ task , $ state );
149142 }
150143
@@ -161,12 +154,10 @@ public function testWriteBatchClearsBatchAfterFlushing(): void
161154
162155 $ reflection = new \ReflectionClass (DoctrineBatchWriterTask::class);
163156 $ batchProperty = $ reflection ->getProperty ('batch ' );
164- $ batchProperty ->setAccessible (true );
165157 $ batchProperty ->setValue ($ task , [$ entity ]); // Add an entity to the batch
166158
167159 // Call writeBatch directly
168160 $ writeBatchMethod = $ reflection ->getMethod ('writeBatch ' );
169- $ writeBatchMethod ->setAccessible (true );
170161 $ writeBatchMethod ->invoke ($ task , $ state );
171162
172163 $ this ->assertCount (0 , $ batchProperty ->getValue ($ task )); // Batch should be empty
@@ -186,12 +177,10 @@ public function testWriteBatchSetsOutput(): void
186177
187178 $ reflection = new \ReflectionClass (DoctrineBatchWriterTask::class);
188179 $ batchProperty = $ reflection ->getProperty ('batch ' );
189- $ batchProperty ->setAccessible (true );
190180 $ batchProperty ->setValue ($ task , [$ entity ]); // Add an entity to the batch
191181
192182 // Call writeBatch directly
193183 $ writeBatchMethod = $ reflection ->getMethod ('writeBatch ' );
194- $ writeBatchMethod ->setAccessible (true );
195184 $ writeBatchMethod ->invoke ($ task , $ state );
196185 }
197186
@@ -209,12 +198,10 @@ public function testWriteBatchThrowsExceptionWhenNoManagerFound(): void
209198
210199 $ reflection = new \ReflectionClass (DoctrineBatchWriterTask::class);
211200 $ batchProperty = $ reflection ->getProperty ('batch ' );
212- $ batchProperty ->setAccessible (true );
213201 $ batchProperty ->setValue ($ task , [$ entity ]); // Add an entity to the batch
214202
215203 // Call writeBatch directly
216204 $ writeBatchMethod = $ reflection ->getMethod ('writeBatch ' );
217- $ writeBatchMethod ->setAccessible (true );
218205 $ writeBatchMethod ->invoke ($ task , $ state );
219206 }
220207}
0 commit comments