【发布时间】:2012-12-29 14:32:59
【问题描述】:
我使用 CakePHP 开发了一个交易应用程序。现在我想使用 PHPUnit 编写单元脚本。我已经在我的服务器上安装了 PHPUnit,并且测试核心测试工作正常。还安装了 Xdebug 用于代码分析。当我要为现有应用程序编写脚本时,它不起作用。我能够在模型中编写登录方法的单元脚本。但无法为其余方法编写脚本。
<?php
App::uses('User', 'Model');
class UserTest extends CakeTestCase {
public $fixtures = array('app.user');
public $dropTables = false;
public function setUp() {
parent::setUp();
$this->User = ClassRegistry::init('User');
}
public function testLogin() {
$result = $this->User->find('count', array(
'conditions' => array(
// making some assumptions about the test data here
'email' => 'test.user@gmail.com',
'password' => 'f1054da373ace628dc73b8ec52eb28072b074940',
),));
$expected = 1;
$this->assertEquals($expected, $result);
}
}
?>
它运行良好。但我无法为其余方法编写脚本。
【问题讨论】:
-
你为什么用
$dropTables = false;? -
您的第一个测试,
testLogin()实际上并没有测试您的任何代码。发布一个实际的测试方法并告诉我们你不能测试什么方法(或者为什么你不能测试它)会很有用。
标签: unit-testing cakephp phpunit