Probably not related. But you break out of the loop before return. I suppose that is wrong? Just return. That will stop the code.
My guess is that the break should be removed.
The expected [Tests\Feature\UnableToSetSystemNumber] mailable was not sent.
Failed asserting that false is true.
/home/vagrant/Sites/stechmax-website/vendor/laravel/framework/src/Illuminate/Support/Testing/Fakes/MailFake.php:48
/home/vagrant/Sites/stechmax-website/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/home/vagrant/Sites/stechmax-website/tests/Feature/SubscriptionTest.php:108
That just proves that it hit the test line. What checks that your logic is correct in your foreach loop?
Also, does the function get called when using factory? , ie, 15 times successfully created a system number?
Agree with @sinnbeck that break is misplaced. You don't need it. WIth it there, the return will be skipped (which makes me suspect this code is never called)
when I add dd('hey') just before the Mail::to function it prints "hey" on the console and when I remove the dd('hey') it prints that error
@snapey Thanks for that correction - you saved my ass from a future bug
@snapey Yes the function created system number 15 successful time, can the returns stops at 15 then the setSystemNumber function moves to the mail::to function