【发布时间】:2014-09-02 19:19:33
【问题描述】:
我有一个用 cakephp 开发的网站,其中包含一个我想用 PHPUnit 测试的组件。
我创建了一个名为 CurrencyConverter 的插件,并在其中放入了一个组件:
Plugin/CurrencyConverter/Controller/Component/CurrencyConverterComponent.php
现在我想测试我的代码。
我已经创建了一个文件 CurrencyConverterTest.php 到:
Test/Case/Controller/Component/CurrencyConverterTest.php
这是测试文件:
<?php
class CurrencyConverterTestCase extends CakeTestCase {
var $uses = null;
public $CurrencyConverter;
function testConverter() {
$this->CurrencyConverter = ClassRegistry::init('CurrencyConverterComponent');
$price = $this->CurrencyConverter->convert('EUR', 'EUR', '1000', 0, 0);
echo($price);
}
}
?>
如果我运行测试返回此错误:
MISSINGTABLEEXCEPTION
Table currency_converter_components for model CurrencyConverterComponent was not found in datasource test.
Test case: CurrencyConverterTestCase(testConverter)
在我的组件中现在没有对数据库的调用,我如何告诉测试不要使用模型?
或者我必须创建一个?
谁能解释我如何在不使用数据库的情况下测试组件?
谢谢
【问题讨论】:
标签: php unit-testing cakephp phpunit