LAW OF DEMETER “The Law of Demeter for functions states that any method of an object should call only methods belonging to itself, any parameters that were passed in to the method, any objects it created, and any directly held component objects. ”
HOW DO YOU TEST THIS? class HipsterApi { ! public function getBands() ! { ! ! return $this->_call('/api/bands', $this->_apiKey); ! } } class HipsterApiWrapper { ! public function __construct($hipsterApi) ! { ! ! $this->_hipsterApi = $hipsterApi; ! } ! public function getBands() ! { ! ! return $this->_hipsterApi->getBands(); ! } }
WHAT NOT TO DO 1. Get a Dependency Injection Container 2. Create a fake version of your object with the static call 3. use the container inside the test