Hi, I'd like to run something before the app terminates basically since I want to run something once and there are some events involved which trigger it multiple times and the last event can't be determined so I need it to run at the end, I know I can use register_shutdown_function but that is problematic since the Laravel is already shutdown by the time that event runs and it's too late to do some stuff there, and the logs won't get saved and many problems occur.
The alternative in Laravel seems to be this:
App::terminating(function(){
});
But then I can't get that to also run in my phpunit tests and that's a huge problem.
Are there any better ways or any workarounds to achieve this? Thanks in advanced.
@Sinnbeck Thanks for responding, It's not related to a phpunit cleanup, I put some side effects in the code to run at the end (here at terminating event), and I want them inside the test so I can assert those side effects.
I need some sort of event that let's me run it manually in the phpunit like app()->runThoseSideEffects and outside the phpunit they should run just at the end when laravel is terminating.
@Sinnbeck Sure thank you.
Here's the simplified usage this code goes in the boot method of AppServiceProvider, somewhere along the way in controller I set a closure to $GLOBALS["some_callback"] and it's supposed to be called at the end, now I know I can call $GLOBALS["some_callback"](); directly in phpunit, but still wanted to know wether there is a better and more elegant way to do this without using the $GLOBALS maybe.
@Sinnbeck Thank you so much for investigating that, it was my next step to make sure the event won't run twice now (once in test and once in teardown), really appreciate that, thanks again!!