有什么区别
$this->userService->getUser();
和
$this->di->get('userService')->getUser();
我在 Controller 中使用它。
我知道第一个变体是一个魔法函数,但它是如何工作的呢? 当我使用 PhpUnit 测试 Controller 时,只有第二个变体有效。
最佳答案
仅在细节上有所不同,当您调用 $this->userService
时,php 会执行魔术方法 __call
并从 di 返回相同的对象。
顺便说一句,测试 Controller 没有好的做法。
关于php - 单元测试 Controller Phalcon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24595102/