gpt4 book ai didi

php - Cakephp 3.0单元测试错误

转载 作者:行者123 更新时间:2023-12-03 23:00:52 24 4
gpt4 key购买 nike

我试图在 CakePHP 3.0 中运行一些单元测试,但不断收到以下错误,这似乎比我自己构建的问题更多?有人有类似的问题吗?测试代码如下本文中的示例: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' => '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="097d6c7a7d6c64686065497d6c7a7d27606c" rel="noreferrer noopener nofollow">[email protected]</a>',
'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

最佳答案

您需要定义 CakePHP 工作所需的常量。这是在应用程序框架中的tests/bootstrap.php 文件中为您完成的:

https://github.com/cakephp/app/blob/master/tests/bootstrap.php#L8

通过包含应用程序 Bootstrap ,它还会在此处创建定义常量:

https://github.com/cakephp/app/blob/master/config/paths.php#L61

关于php - Cakephp 3.0单元测试错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29490794/

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