If you have been into test-driven driven development especially in PHP, you probably know that static methods are hard to test. Mocking static calls have been deprecated with PHPUnit.
How to do guys mock static calls? And if statics are bad for TDD, how Laravel tests all its static calls?
Yes, Laravel uses a lot of facades, but you can easily test everything. I'd recommend you to read a "Laravel Testing Decoded" by Jeffrey Way, it will answer all of your questions.
If you don't want to use facades, you don't have to, because Laravel offers a lot of global helpers (like redirect()
for Redirect::
, auth()
for Auth::
, session()
for Session::
etc). Also, you can always use DI:
public function index(User $user)
{
$users = $user->all();
Instead of:
$users = User::all();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With