gpt4 book ai didi

unit-testing - Zend Framework 在单元测试中没有正确处理 Camel 案例 Controller

转载 作者:行者123 更新时间:2023-12-04 04:07:08 24 4
gpt4 key购买 nike

我正在做我的第一个 ZF 项目,但有点卡住了。我有一个名为“WebServiceController”的 Controller ,我对 WebServiceController 进行了单元测试,但是当我运行测试时,它没有正确断言 Controller 。我的测试代码是:

public function testIndexAction() {
$params = array('action' => 'index', 'controller' => 'WebService', 'module' => 'default');
$url = $this->url($this->urlizeOptions($params));
$this->dispatch($url);

// assertions
$this->assertModule($params['module']);
$this->assertController($params['controller']);
$this->assertAction($params['action']);
$this->assertQueryContentContains(
'div#view-content p',
'View script for controller <b>' . $params['controller'] . '</b> and script/action name <b>' . $params['action'] . '</b>'
);
}

我得到的错误是:

1) WebServiceControllerTest::testIndexAction
断言上次使用的 Controller <"Web-Service"> 是 "WebService"失败

看起来它试图断言 Controller 是“Web-Service”而不是“WebService”。任何人都可以指出我正确的方向吗?

提前致谢。

齐亚德

附言我正在使用 ZF 1.11.5

最佳答案

在 Zend Framework 中, Controller 的驼峰命名在 URL 中重写:
WebService在类名中变成 web-service在网址中。

这是正常行为,请参阅 http://framework.zend.com/manual/1.12/en/zend.controller.basics.html :

Since humans are notoriously inconsistent at maintaining case sensitivity when typing links, Zend Framework actually normalizes path information to lowercase. This, of course, will affect how you name your controller and actions... or refer to them in links. If you wish to have your controller class or action method name have multiple MixedCasedWords or camelCasedWords, you will need to separate those words on the url with either a '-' or '.' (though you can configure the character used). As an example, if you were going to the action in FooBarController::bazBatAction(), you'd refer to it on the url as /foo-bar/baz-bat or /foo.bar/baz.bat.

关于unit-testing - Zend Framework 在单元测试中没有正确处理 Camel 案例 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5789754/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com