php - 单元测试 Controller Phalcon

标签 php testing phpunit phalcon

有什么区别

$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/

相关文章:

php - symfony2 phpunit 测试出现 LogicException : The selected node does not have a form ancestor. 错误

php - 在mysql中将两列合并为一列

javascript - php获取输入字段值和span值

Django : testing static files

java - 如何创建只能用于测试的方法

php - 如何测试 Laravel 5 Controller 方法

php - 选择选项下拉菜单并插入到 PHP 函数中

php - 从 PHP 数组结果中删除字符串长度值

java - 是否有任何适用于 Java 的假文件系统框架?

testing - Selenium Webdriver 异常 : waitForPageToLoad is not a valid webdriver command?