dtdfl62844 2015-04-07 11:44
浏览 31

Cakephp 3.0单元测试错误

I am trying to run some unit tests in CakePHP 3.0 but keep getting the following errors, which seem to be more Cake problems than one I constructed myself? Anyone have a similar issue? Test code is following samle in this article: 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());
    }

Response:

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
  • 写回答

3条回答 默认 最新

  • duanqian6295 2015-04-07 13:59
    关注

    You need to define the constants that are required for CakePHP to work. This is done for you in the tests/bootstrap.php file in the application skeleton:

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

    By including the application bootstrap, it also creates defines the constants here:

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

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用