- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试为我正在编写的 ZF 应用程序编写一些测试用例,但我似乎无法超越这一点。
我扩展了 Zend_Test_PHPUnit_ControllerTestCase
,添加了以下内容:
public function setUp() {
$this->bootstrap = new Zend_Application('testing',
APPLICATION_PATH . '/configs/application.ini');
parent::setUp();
}
它起作用了,它初始化了 Zend Autoloader,允许我在我的库中加载其他类以及 Zend 类。所以我设置了一个测试:
public function testUserUnauthorized() {
$this->dispatch('/api/user');
//Assertions...
}
可悲的是,测试从未通过 dispatch 。相反,它给了我一个错误:
Fatal error: Class 'App_Model_User' not found in ....Action.php
Action.php 是一个扩展 Zend_Controller_Action
的类。其中,有一个函数使用 App_Model_User
对登录用户进行身份验证。自从 Autoloader 工作以来,我从来不需要添加 require_once
。这是奇怪的部分:它通过我的浏览器工作。只是不在 PHPUnit 中。
所以我转储了使用 Zend Autoloader 注册的 Autoloader:
public function testUserUnauthorized() {
print_r(Zend_Loader_Autoloader::getInstance()->getAutoloaders());
exit;
$this->dispatch('/api/user');
}
它显示了我所有的模块,以及 View 、 Controller 、模型等的命名空间。我通过浏览器做了同样的事情,并且转储匹配。
最佳答案
Zend Autoloader 需要将 App_ 添加为自动加载前缀才能按预期工作,如下所示:
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace("App_");
关于php - Zend 自动加载 PHPUnit 中的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10846859/
我可以在所有 PHPUnit 测试完成后自动运行 PHP 脚本吗? 我想在所有测试完成后报告一些非致命问题(即正确但次优的测试结果)。 最佳答案 假设您可以检测到此类次优结果,PHPUnit(v9 及
假设我要测试三种状态下的数据库一致性: 插入数据后 - 我想确保已将一定数量的行插入到数据库表中。 当数据更新后-我想重复行数量测试(数量必须与插入后相同) 删除数据时 - 我想确保所有数据都已删除。
在 pear.phpunit.de/PHPUnit 中安装 PHPUnit 未知 channel pear.phpunit.de 时出错 无效的包名称/包文件 "Debian-4 操作系统上的 pea
谁能给我解释一下使用名为 phpunit.xml.dist 或 phpunit.xml 的 PHPunit 配置文件有什么区别。 official documentation提到两个名字: PHPUn
如果我只想使用来自数据提供者的一个数据运行测试,我该怎么做? 我在这个线程上尝试了解决方案,但没有奏效 Cannot run single test with data provider in PHP
如何编写自定义断言,例如 assertFoo($expected, $actual) ,它的行为类似于关于错误“堆栈跟踪”的内置断言? 我目前定义了以下方法(在扩展 PHPUnit_Framework
我想在我的 Windows 服务器上安装 PHPUnit 3.7。我遵循了各种说明 here并以 PHPUnit 3.4.1 结束。当我尝试使用以下方法再次安装它时: pear update chan
我尝试在 PhpUnit 的 WebTestCase 中发送原始数据,但它不起作用: $jsonEvent = '{ "type": "invoice.payment_succeeded"
我收到了 PHPUnit 错误的代码覆盖率报告,我相信这是 XDebug 的一个错误。 如何配置 PHPUnit 以使用 one of its other drivers ,即PHPDBG? (我使用
我正在我的第一个项目中使用 PHPUnit 进行单元测试。事情进展顺利;但是,我已经开始通过最近的测试获得以下输出: .........................................
我刚刚学习如何使用 PHPUnit。我从命令行运行它,在结果中我得到OK,但是有问题!测试:5,断言:15,警告:2,弃用:5。 我不知道如何让它解释导致弃用和警告计数的原因。 如何找出测试代码中导致
是否有比 $this->assertTrue(false) 更官方的方法来强制 phpunit 失败? 最佳答案 我相信这应该在测试用例中起作用: $this->fail('Message'); 关于
我正在尝试为我的 Silex 应用程序编写一些测试,但遇到了问题。 我有以下 phpunit.xml 文件 ./
目前,我正在尝试使用命令行 phpunittests/Unit/ExampleTest 在 Laravel 项目上使用 phpunit 运行一些简单的单元测试。但它只运行第一种方法。有人有解决办法吗?
我的一些测试用例使用自定义测试库。而且这些测试用例非常慢。所以我想只在构建服务器中运行它们,而不是在我的本地服务器中运行它们。我想在本地运行其他测试。 以下是目录结构。 slow 目录中的那些是应该排
我有以下测试/文件夹: tests/ ClassOne.test.php ClassTwo.test.php ClassThree.test.php 我必须将以下 setUp() 和
我使用 phpunit 的测试套件功能来组织我的测试。我这样做是为了以后能够并行运行测试。 对于不同的目录,这是相对直接的。例如,我可以按捆绑拆分测试套件。 tests/BundleOne
我必须用内部数组测试一个数组。 我的数组如下所示。 $testdata=Array ( [0] => Array ( [
问题:为什么 PHPUnit 似乎在严格模式下运行? 问题: PHPUnit 4.3.1 by Sebastian Bergmann. Configuration read from /full/pa
我已经通过 Composer 安装了 PHPUnit,并将其设置为通过设置运行单元测试。 但是当我运行测试时,测试报告器出现以下错误(tets 执行得很好): Unable to attach tes
我是一名优秀的程序员,十分优秀!