Summary
A
PHP Dependency Injector library to support Inversion of Control design pattern.
Notes
- The idea is to avoid creating objects inside of objects as that tightly couples them and makes it difficult to unit test them independently.
- By using the Inversion of Control (IoC) design pattern the objects are passed into the constructor making it possible to create mock objects whose attributes and functions can be independently determined.
- For example if object A referenced object B, IoC would allow a mocked version of B to be passed to A. If A used the results of B's isOpen function the mock of object B could be set to return true to test one branch of logic in A then set to false to test another without having to deal with the internal logic of B.
- This allows the unit test to isolate the logic of a given class and focus exclusively on it.
- I'd like to understand more about how it actually works. The documentation states that it "recursively instantiates class dependencies" the process by which it accomplished this is still a little mysterious.