Mocking a Demeter Chain in PHP the Shortcut You Didn’t Know You Had
Ever tried to mock a Demeter chain in PHP? It’s like trying to thread a needle with a rope. Let’s break it down with an example using Laravel.
Example of a Demeter Chain
Imagine you’re working with Laravel, and you have this glorious chain:
$order = Order::find($id);
$status = $order->payment->transaction->status;
Here, we’re grabbing an Order, navigating through its payment, then through its transaction, to get the status.
Now you want to test something, and this chain decides to make your life miserable:
2 minutes to read