@@ -41,6 +41,23 @@ function it_is_initializable(): void
4141 $ this ->shouldHaveType (FlashHelper::class);
4242 }
4343
44+ function it_adds_success_flashes_with_custom_message (
45+ Request $ request ,
46+ SessionInterface $ session ,
47+ FlashBagInterface $ flashBag ,
48+ ): void {
49+ $ operation = (new Create ())->withResource (new ResourceMetadata (alias: 'app.dummy ' , name: 'dummy ' , applicationName: 'app ' ));
50+ $ context = new Context (new RequestOption ($ request ->getWrappedObject ()));
51+
52+ $ request ->getSession ()->willReturn ($ session );
53+
54+ $ session ->getBag ('flashes ' )->willReturn ($ flashBag );
55+
56+ $ flashBag ->add ('success ' , 'Custom message. ' )->shouldBeCalled ();
57+
58+ $ this ->addSuccessFlash ($ operation , $ context , 'Custom message. ' );
59+ }
60+
4461 function it_adds_success_flashes_with_specific_message (
4562 Request $ request ,
4663 SessionInterface $ session ,
@@ -91,7 +108,7 @@ function it_adds_success_flashes_with_fallback_message(
91108 $ this ->addSuccessFlash ($ operation , $ context );
92109 }
93110
94- function it_adds_success_flashes_with_custom_message (
111+ function it_adds_success_flashes_with_custom_message_on_its_operation (
95112 Request $ request ,
96113 SessionInterface $ session ,
97114 FlashBagInterface $ flashBag ,
@@ -186,6 +203,73 @@ function it_adds_success_flashes_with_humanized_message_and_plural_name_on_bulk_
186203 $ this ->addSuccessFlash ($ operation , $ context );
187204 }
188205
206+ function it_adds_error_flashes_with_custom_message (
207+ Request $ request ,
208+ SessionInterface $ session ,
209+ FlashBagInterface $ flashBag ,
210+ ): void {
211+ $ operation = (new Create ())->withResource (new ResourceMetadata (alias: 'app.dummy ' , name: 'dummy ' , applicationName: 'app ' ));
212+ $ context = new Context (new RequestOption ($ request ->getWrappedObject ()));
213+
214+ $ request ->getSession ()->willReturn ($ session );
215+
216+ $ session ->getBag ('flashes ' )->willReturn ($ flashBag );
217+
218+ $ flashBag ->add ('error ' , 'Custom error message. ' )->shouldBeCalled ();
219+
220+ $ this ->addErrorFlash ($ operation , $ context , 'Custom error message. ' );
221+ }
222+
223+ function it_adds_error_flashes_with_specific_message (
224+ Request $ request ,
225+ SessionInterface $ session ,
226+ FlashBagInterface $ flashBag ,
227+ TranslatorBagInterface $ translator ,
228+ MessageCatalogueInterface $ messageCatalogue ,
229+ ): void {
230+ $ operation = (new Create ())->withResource (new ResourceMetadata (alias: 'app.dummy ' , name: 'dummy ' , applicationName: 'app ' ));
231+ $ context = new Context (new RequestOption ($ request ->getWrappedObject ()));
232+
233+ $ request ->getSession ()->willReturn ($ session );
234+
235+ $ session ->getBag ('flashes ' )->willReturn ($ flashBag );
236+
237+ $ translator ->getCatalogue ()->willReturn ($ messageCatalogue );
238+
239+ $ messageCatalogue ->has ('app.dummy.create_error ' , 'flashes ' )->willReturn (true )->shouldBeCalled ();
240+
241+ $ translator ->trans ('app.dummy.create_error ' , ['%resource% ' => 'Dummy ' ], 'flashes ' )->willReturn ('Cannot create Dummy resource. ' )->shouldBeCalled ();
242+
243+ $ flashBag ->add ('error ' , 'Cannot create Dummy resource. ' )->shouldBeCalled ();
244+
245+ $ this ->addErrorFlash ($ operation , $ context );
246+ }
247+
248+ function it_adds_error_flashes_with_fallback_message (
249+ Request $ request ,
250+ SessionInterface $ session ,
251+ FlashBagInterface $ flashBag ,
252+ TranslatorBagInterface $ translator ,
253+ MessageCatalogueInterface $ messageCatalogue ,
254+ ): void {
255+ $ operation = (new Create ())->withResource (new ResourceMetadata (alias: 'app.dummy ' , name: 'dummy ' , applicationName: 'app ' ));
256+ $ context = new Context (new RequestOption ($ request ->getWrappedObject ()));
257+
258+ $ request ->getSession ()->willReturn ($ session );
259+
260+ $ session ->getBag ('flashes ' )->willReturn ($ flashBag );
261+
262+ $ translator ->getCatalogue ()->willReturn ($ messageCatalogue );
263+
264+ $ messageCatalogue ->has ('app.dummy.create_error ' , 'flashes ' )->willReturn (false )->shouldBeCalled ();
265+
266+ $ translator ->trans ('sylius.resource.create_error ' , ['%resource% ' => 'Dummy ' ], 'flashes ' )->willReturn ('Cannot create Dummy resource. ' )->shouldBeCalled ();
267+
268+ $ flashBag ->add ('error ' , 'Cannot create Dummy resource. ' )->shouldBeCalled ();
269+
270+ $ this ->addErrorFlash ($ operation , $ context );
271+ }
272+
189273 function it_translates_flashes_from_event_when_translator_is_not_a_bag (
190274 Request $ request ,
191275 SessionInterface $ session ,
0 commit comments