【发布时间】:2015-06-12 00:04:17
【问题描述】:
我正在尝试在 CakePHP 3.0 中运行一些单元测试,但不断收到以下错误,这似乎是比我自己构建的更多 Cake 问题?有人有类似的问题吗?本文测试代码如下:http://book.cakephp.org/3.0/en/development/testing.html
namespace App\Test\TestCase\Controller;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\IntegrationTestCase;
/**
* App\Controller\UsersController Test Case
*/
class UsersControllerTest extends IntegrationTestCase
{
/**
* Test add method
*
* @return void
*/
public function testAdd()
{
$data = [
'username' => 'testusername',
'password' => 'testpassword',
'email' => 'testemail@test.ie',
'location_id' => 5,
'gender' => 'Male',
'info' => 'test info'
];
$this->post('/users', $data);
$this->assertResponseSuccess();
$users = TableRegistry::get('Users');
$query = $users->find()->where(['username' => $data['username']]);
$this->assertEquals(1, $query->count());
}
回复:
1) App\Test\TestCase\Controller\UsersControllerTest::testIndex
Use of undefined constant TMP - assumed 'TMP'
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\Network\Session.php:141
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\Network\Session.php:95
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCas
e.php:340
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCas
e.php:267
C:\wamp\www\mysite\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCas
e.php:188
【问题讨论】:
-
至少添加您的测试代码(您的测试代码可能有助于了解哪些常量
TMP未初始化) -
现在添加测试代码。
标签: php unit-testing cakephp phpunit cakephp-3.0