小编Sho*_*ine的帖子

ZF2单元测试认证

我正在学习单元测试,我试图解决以下问题:

Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for zfcUserAuthentication
Run Code Online (Sandbox Code Playgroud)

...使用给出的唯一答案:

简单的ZF2单元使用ZfcUser测试控制器

所以我的setUp函数看起来一样.不幸的是,我收到错误消息:

Zend\Mvc\Exception\InvalidPluginException: Plugin of type Mock_ZfcUserAuthentication_868bf824 is invalid; must implement Zend\Mvc\Controller\Plugin\PluginInterface
Run Code Online (Sandbox Code Playgroud)

它是由代码的这一部分引起的(在我的代码中以相同的方式分开):

$this -> controller->getPluginManager()
->setService('zfcUserAuthentication', $authMock); // Error refers to this line.
Run Code Online (Sandbox Code Playgroud)

$ authMock对象显然没有实现plugininterface,我需要实现它来传递到setService.

$ authMock是不是要通过那里,因为它用于单元测试?我应该使用不同的(面向单元测试的)setService方法吗?

我需要一种方法来处理登录到我的应用程序,或者我的单元测试毫无意义.

谢谢你的建议.

===编辑(11/02/2013)===

我想专注于这一部分以澄清,因为我认为这是问题领域:

// Getting mock of authentication object, which is used as a plugin.
$authMock = $this->getMock('ZfcUser\Controller\Plugin\ZfcUserAuthentication');

// Some expectations of the authentication service.
$authMock   -> expects($this->any())
    -> method('hasIdentity')
    -> will($this->returnValue(true));  

$authMock   -> expects($this->any())
    -> method('getIdentity')
    -> …
Run Code Online (Sandbox Code Playgroud)

phpunit zend-framework2 zfcuser

23
推荐指数
1
解决办法
2867
查看次数

ZF2服务定位器

我对zf2很新,我正在尝试它.我有一个视图助手,我需要它来访问一个表对象.在我的控制器中我可以运行:

$this->getServiceLocator();
Run Code Online (Sandbox Code Playgroud)

但理想情况下,我会在我的视图助手中运行它.不幸的是,我似乎无法从我的视图助手中访问它.我尝试将其传递给构造函数,在module.config.php中配置工厂方法,但是当我尝试这样时,Zend将不再将tablegateway对象传递到我从模块的Module中的服务工厂方法创建的模型对象中. php文件.这似乎是因为它不再调用工厂方法,并选择在没有任何参数的情况下运行实例化.

我不确定我理解为什么视图工厂方法会影响具有不同名称的不同工厂方法集.

谁能告诉我我在做什么有什么问题?我可以提供更多细节,但在这一点上,我不清楚在不提供整个代码库的情况下哪些细节实际上很重要.

谢谢.

zend-framework2

3
推荐指数
1
解决办法
9838
查看次数

NodeJS获取承诺回调挂起

我有这个代码:

fetch(url).then(response => {
  const json = response.json();
  console.log('simplest possible fetch', json, json.where);
});
Run Code Online (Sandbox Code Playgroud)

在控制台中,我得到:

simplest possible fetch Promise {[[PromiseStatus]]: "pending", [[PromiseValue]]: undefined} undefined
Run Code Online (Sandbox Code Playgroud)

大部分时间都这样.有时我会获得"成功"状态.对我而言,这意味着在获取提取已解决之前正在运行回调.

我希望只有在fetch完成时才能运行该函数.我该怎么做呢?

javascript node.js promise

3
推荐指数
1
解决办法
710
查看次数

ZF2登录转发

我在控制器中有一个功能,需要检查用户是否已登录(我正在使用zfcuser模块),如果没有,则显示登录屏幕.

我的理解是我应该运行这个:

return $this->forward()->dispatch('zfcuser', array('action' => 'authenticate'));
Run Code Online (Sandbox Code Playgroud)

不幸的是,这改变了网址.我想显示登录屏幕,并允许用户登录而不更改网址.通过扩展,这意味着我还希望将用户重定向回同一页面,而不是转到/user页面.

我怎样才能实现这两件事?

php zend-framework2 zfcuser

1
推荐指数
1
解决办法
2949
查看次数

Bash/sed:没有那个文件或目录

我有一个名为 script.sh 的脚本:

FILE=$1
sed -i.bak "s|needle|pin|g" $FILE
Run Code Online (Sandbox Code Playgroud)

如果我像这样运行它:

bash ./script.sh /var/www/path/to/file
Run Code Online (Sandbox Code Playgroud)

我得到这个回应:

: No such file or directoryth/to/file
Run Code Online (Sandbox Code Playgroud)

如果我自己运行sed,则通过相同的路径:

sed -i.bak "s|needle|pin|g" "/var/www/path/to/file"
Run Code Online (Sandbox Code Playgroud)

它工作正常(甚至正确替换值)。

我究竟做错了什么?

额外的观察:我假设它告诉我入口路径是错误的,但很难说,因为它说“:没有这样的文件或目录/到/文件”,这向我表明其他东西是错误的。也许与回车有关?

bash sed

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

zend-framework2 ×3

zfcuser ×2

bash ×1

javascript ×1

node.js ×1

php ×1

phpunit ×1

promise ×1

sed ×1