@@ -142,4 +142,50 @@ public function can_create_embeddable(): void
142142 $ this ->assertNull ($ object1 ->getValue ());
143143 $ this ->assertSame ('an address ' , $ object2 ->getValue ());
144144 }
145+
146+ public function can_delay_flush (): void
147+ {
148+ AnonymousFactory::new (Post::class)->assert ()->empty ();
149+ AnonymousFactory::new (Category::class)->assert ()->empty ();
150+
151+ AnonymousFactory::delayFlush (function () {
152+ AnonymousFactory::new (Post::class)->create ([
153+ 'title ' => 'title ' ,
154+ 'body ' => 'body ' ,
155+ 'category ' => AnonymousFactory::new (Category::class, ['name ' => 'name ' ]),
156+ ]);
157+
158+ AnonymousFactory::new (Post::class)->assert ()->empty ();
159+ AnonymousFactory::new (Category::class)->assert ()->empty ();
160+ });
161+
162+ AnonymousFactory::new (Post::class)->assert ()->count (1 );
163+ AnonymousFactory::new (Category::class)->assert ()->count (1 );
164+ }
165+
166+ /**
167+ * @test
168+ */
169+ public function auto_refresh_is_disabled_during_delay_flush (): void
170+ {
171+ AnonymousFactory::new (Post::class)->assert ()->empty ();
172+ AnonymousFactory::new (Category::class)->assert ()->empty ();
173+
174+ AnonymousFactory::delayFlush (function () {
175+ $ post = AnonymousFactory::new (Post::class)->create ([
176+ 'title ' => 'title ' ,
177+ 'body ' => 'body ' ,
178+ 'category ' => AnonymousFactory::new (Category::class, ['name ' => 'name ' ]),
179+ ]);
180+
181+ $ post ->setTitle ('new title ' );
182+ $ post ->setBody ('new body ' );
183+
184+ AnonymousFactory::new (Post::class)->assert ()->empty ();
185+ AnonymousFactory::new (Category::class)->assert ()->empty ();
186+ });
187+
188+ AnonymousFactory::new (Post::class)->assert ()->count (1 );
189+ AnonymousFactory::new (Category::class)->assert ()->count (1 );
190+ }
145191}
0 commit comments