Cakephp 致命错误:对非对象调用成员函数create()

Cakephp 致命错误:对非对象调用成员函数create(),cakephp,Cakephp,我需要在控制器中测试add方法,我使用cakephp框架和phpunit进行测试,控制器中的方法如下所示: public function add() { $this->CategoryProblem->create(); if ($this->CategoryProblem->save($this->request->data)) { $message = 'Saved';

我需要在控制器中测试add方法,我使用cakephp框架和phpunit进行测试,控制器中的方法如下所示:

public function add() {

            $this->CategoryProblem->create();
            if ($this->CategoryProblem->save($this->request->data)) {
                $message = 'Saved';
            } else {
                $message = 'Error';
            }
            $this->set(array(
            'message' => $message,
            '_serialize' => array('message')
            ));

    }
测试结果如下所示:

public function testAdd() {
        $data = array(
            'CategoryProblems' => array(
                'id' => '15',
                'parent_id'=>null,
                'modified'=> '',
                'deleted'=>'',
                'name'=>'raspado',
                'description'=>null,

            ),
        );

        $this->testAction('/categoryproblems/add',array('data'=> $data ));
        $result = $this->_testAction('/categoryproblems.json',array('method'=>'pot','data'=>array(json_decode('message'))));
        $this->assertTrue($result,'Saved');

            debug($result);
    }
当我运行测试时,出现以下错误:

C:\xampp_183\php\php.exe C:\xampp_183\htdocs\MDCW\Projects\services\cakeunit4phpstorm.php C:/Users/yaima.vazquez/AppData/Local/Temp/ide-phpunit.php --cake-case=Controller\CategoryProblemsController --cake-app --no-configuration C:\xampp_183\htdocs\MDCW\Projects\services\app\Test\Case\Controller
Testing started at 2:54 PM ...
<pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f626e32-trace').style.display = (document.getElementById('cakeErr56c772f626e32-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: Cannot modify header information - headers already sent by (output started at C:\xampp_183\php\pear\PHPUnit\Util\Printer.php:172) [<b>APP\Controller\AppController.php</b>, line <b>41</b>]<div id="cakeErr56c772f626e32-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f626e32-code').style.display = (document.getElementById('cakeErr56c772f626e32-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f626e32-context').style.display = (document.getElementById('cakeErr56c772f626e32-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr56c772f626e32-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">{</span></span></code>
<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'params'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Router</span><span style="color: #007700">::</span><span style="color: #0000BB">getParams</span><span style="color: #007700">());</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Access-Control-Allow-Origin:*'</span><span style="color: #007700">);</span></span></code></span></pre><pre class="stack-trace">header - [internal], line ??
AppController::beforeFilter() - APP\Controller\AppController.php, line 41
call_user_func - [internal], line ??
CakeEventManager::dispatch() - CORE\Cake\Event\CakeEventManager.php, line 243
Controller::startupProcess() - CORE\Cake\Controller\Controller.php, line 676
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 189
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 167
ControllerTestCase::_testAction() - CORE\Cake\TestSuite\ControllerTestCase.php, line 279
ControllerTestCase::__call() - CORE\Cake\TestSuite\ControllerTestCase.php, line 191
CategoryProblemsControllerTest::testAction() - APP\Test\Case\Controller\CategoryProblemsControllerTest.php, line 26
CategoryProblemsControllerTest::testIndex() - APP\Test\Case\Controller\CategoryProblemsControllerTest.php, line 26
ReflectionMethod::invokeArgs() - [internal], line ??
PHPUnit_Framework_TestCase::runTest() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 976
PHPUnit_Framework_TestCase::runBare() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 831
PHPUnit_Framework_TestResult::run() - C:\xampp_183\php\pear\PHPUnit\Framework\TestResult.php, line 648
PHPUnit_Framework_TestCase::run() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 776
CakeTestCase::run() - CORE\Cake\TestSuite\CakeTestCase.php, line 82</pre></div></pre><pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f627e23-trace').style.display = (document.getElementById('cakeErr56c772f627e23-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: Cannot modify header information - headers already sent by (output started at C:\xampp_183\php\pear\PHPUnit\Util\Printer.php:172) [<b>APP\Controller\AppController.php</b>, line <b>42</b>]<div id="cakeErr56c772f627e23-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f627e23-code').style.display = (document.getElementById('cakeErr56c772f627e23-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f627e23-context').style.display = (document.getElementById('cakeErr56c772f627e23-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr56c772f627e23-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">set</span><span style="color: #007700">(</span><span style="color: #DD0000">'params'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Router</span><span style="color: #007700">::</span><span style="color: #0000BB">getParams</span><span style="color: #007700">());</span></span></code>
<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Access-Control-Allow-Origin:*'</span><span style="color: #007700">);</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Access-Control-Allow-Headers:Content-Type&nbsp;,Content-Range,&nbsp;Content-Disposition,&nbsp;Content-Description'</span><span style="color: #007700">);</span></span></code></span></pre><pre class="stack-trace">header - [internal], line ??
AppController::beforeFilter() - APP\Controller\AppController.php, line 42
call_user_func - [internal], line ??
CakeEventManager::dispatch() - CORE\Cake\Event\CakeEventManager.php, line 243
Controller::startupProcess() - CORE\Cake\Controller\Controller.php, line 676
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 189
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 167
ControllerTestCase::_testAction() - CORE\Cake\TestSuite\ControllerTestCase.php, line 279
ControllerTestCase::__call() - CORE\Cake\TestSuite\ControllerTestCase.php, line 191
CategoryProblemsControllerTest::testAction() - APP\Test\Case\Controller\CategoryProblemsControllerTest.php, line 26
CategoryProblemsControllerTest::testIndex() - APP\Test\Case\Controller\CategoryProblemsControllerTest.php, line 26
ReflectionMethod::invokeArgs() - [internal], line ??
PHPUnit_Framework_TestCase::runTest() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 976
PHPUnit_Framework_TestCase::runBare() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 831
PHPUnit_Framework_TestResult::run() - C:\xampp_183\php\pear\PHPUnit\Framework\TestResult.php, line 648
PHPUnit_Framework_TestCase::run() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 776
CakeTestCase::run() - CORE\Cake\TestSuite\CakeTestCase.php, line 82</pre></div></pre><pre class="cake-error"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f6288ab-trace').style.display = (document.getElementById('cakeErr56c772f6288ab-trace').style.display == 'none' ? '' : 'none');"><b>Warning</b> (2)</a>: Cannot modify header information - headers already sent by (output started at C:\xampp_183\php\pear\PHPUnit\Util\Printer.php:172) [<b>APP\Controller\AppController.php</b>, line <b>43</b>]<div id="cakeErr56c772f6288ab-trace" class="cake-stack-trace" style="display: none;"><a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f6288ab-code').style.display = (document.getElementById('cakeErr56c772f6288ab-code').style.display == 'none' ? '' : 'none')">Code</a> <a href="javascript:void(0);" onclick="document.getElementById('cakeErr56c772f6288ab-context').style.display = (document.getElementById('cakeErr56c772f6288ab-context').style.display == 'none' ? '' : 'none')">Context</a><pre id="cakeErr56c772f6288ab-code" class="cake-code-dump" style="display: none;"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Access-Control-Allow-Origin:*'</span><span style="color: #007700">);</span></span></code>
<code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Access-Control-Allow-Headers:Content-Type&nbsp;,Content-Range,&nbsp;Content-Disposition,&nbsp;Content-Description'</span><span style="color: #007700">);</span></span></code>
<span class="code-highlight"><code><span style="color: #000000"><span style="color: #0000BB">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Access-Control-Allow-Methods:GET,&nbsp;POST,&nbsp;PUT,&nbsp;DELETE,&nbsp;OPTIONS'</span><span style="color: #007700">);</span></span></code></span></pre><pre class="stack-trace">header - [internal], line ??
AppController::beforeFilter() - APP\Controller\AppController.php, line 43
call_user_func - [internal], line ??
CakeEventManager::dispatch() - CORE\Cake\Event\CakeEventManager.php, line 243
Controller::startupProcess() - CORE\Cake\Controller\Controller.php, line 676
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 189
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 167
ControllerTestCase::_testAction() - CORE\Cake\TestSuite\ControllerTestCase.php, line 279
ControllerTestCase::__call() - CORE\Cake\TestSuite\ControllerTestCase.php, line 191
CategoryProblemsControllerTest::testAction() - APP\Test\Case\Controller\CategoryProblemsControllerTest.php, line 26
CategoryProblemsControllerTest::testIndex() - APP\Test\Case\Controller\CategoryProblemsControllerTest.php, line 26
ReflectionMethod::invokeArgs() - [internal], line ??
PHPUnit_Framework_TestCase::runTest() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 976
PHPUnit_Framework_TestCase::runBare() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 831
PHPUnit_Framework_TestResult::run() - C:\xampp_183\php\pear\PHPUnit\Framework\TestResult.php, line 648
PHPUnit_Framework_TestCase::run() - C:\xampp_183\php\pear\PHPUnit\Framework\TestCase.php, line 776
CakeTestCase::run() - CORE\Cake\TestSuite\CakeTestCase.php, line 82</pre></div></pre>
Fatal error: Call to a member function create() on a non-object in C:\xampp_183\htdocs\MDCW\Projects\services\app\Controller\CategoryProblemsController.php on line 53

Process finished with exit code 255
C:\xampp_183\php\php.exe C:\xampp_183\htdocs\MDCW\Projects\services\cakeunit4hpstorm.php C:/Users/yaima.vazquez/AppData/Local/Temp/ide-phpunit.php--cake case=Controller\categoryprobblemscocontroller--cake-app--无配置C:\xampp_183\htdocs\MDCW\Projects\app\app\Test\case\Controller
测试于下午2:54开始。。。
:无法修改标题信息-标题已由发送(输出从C:\xampp_183\php\pear\PHPUnit\Util\Printer.php:172开始)[APP\Controller\AppController.php,第41行]
{
$此集合('params',Router::getParams());
header('Access-Control-Allow-Origin:');
header-[内部],第行?? AppController::beforeFilter()-APP\Controller\AppController.php,第41行 调用用户函数-[内部],行?? CakeEventManager::dispatch()-CORE\Cake\Event\CakeEventManager.php,第243行 Controller::startupProcess()-CORE\Cake\Controller\Controller.php,第676行 Dispatcher::_invoke()-CORE\Cake\Routing\Dispatcher.php,第189行 Dispatcher::Dispatcher()-CORE\Cake\Routing\Dispatcher.php,第167行 ControllerTestCase::_testAction()-CORE\Cake\TestSuite\ControllerTestCase.php,第279行 ControllerTestCase::\uu call()-CORE\Cake\TestSuite\ControllerTestCase.php,第191行 CategoryProblemsControllerTest::testAction()-APP\Test\Case\Controller\CategoryProblemsControllerTest.php,第26行 CategoryProblemsControllerTest::testIndex()-APP\Test\Case\Controller\CategoryProblemsControllerTest.php,第26行 ReflectionMethod::invokeArgs()-[internal],第行?? PHPUnit\u Framework\u TestCase::runTest()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第976行 PHPUnit\u Framework\u TestCase::runBare()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第831行 PHPUnit\u Framework\u TestResult::run()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestResult.php,第648行 PHPUnit\u Framework\u TestCase::run()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第776行 CakeTestCase::run()-CORE\Cake\TestSuite\CakeTestCase.php,第82行:无法修改头信息-已发送的头(输出开始于C:\xampp183\php\pear\PHPUnit\Util\Printer.php:172)[APP\Controller\AppController.php,第42行]
$this set('params',Router::getParams());
标题('Access-Control-Allow-Origin:*);
header('Access-Control-Allow-Headers:Content-Type,Content-Range,Content-Disposition,Content-Description');
header-[internal],line?? AppController::beforeFilter()-APP\Controller\AppController.php,第42行 调用用户函数-[内部],行?? CakeEventManager::dispatch()-CORE\Cake\Event\CakeEventManager.php,第243行 Controller::startupProcess()-CORE\Cake\Controller\Controller.php,第676行 Dispatcher::_invoke()-CORE\Cake\Routing\Dispatcher.php,第189行 Dispatcher::Dispatcher()-CORE\Cake\Routing\Dispatcher.php,第167行 ControllerTestCase::_testAction()-CORE\Cake\TestSuite\ControllerTestCase.php,第279行 ControllerTestCase::\uu call()-CORE\Cake\TestSuite\ControllerTestCase.php,第191行 CategoryProblemsControllerTest::testAction()-APP\Test\Case\Controller\CategoryProblemsControllerTest.php,第26行 CategoryProblemsControllerTest::testIndex()-APP\Test\Case\Controller\CategoryProblemsControllerTest.php,第26行 ReflectionMethod::invokeArgs()-[internal],第行?? PHPUnit\u Framework\u TestCase::runTest()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第976行 PHPUnit\u Framework\u TestCase::runBare()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第831行 PHPUnit\u Framework\u TestResult::run()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestResult.php,第648行 PHPUnit\u Framework\u TestCase::run()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第776行 CakeTestCase::run()-CORE\Cake\TestSuite\CakeTestCase.php,第82行:无法修改标题信息-已由发送的标题(输出开始于C:\xampp183\php\pear\PHPUnit\Util\Printer.php:172)[APP\Controller\AppController.php,第43行]
标题('Access-Control-Allow-Origin:');
header('Access-Control-Allow-Headers:Content-Type、Content-Range、Content-Disposition、Content-Description');
header('Access-Control-Allow-Methods:GET、POST、PUT、DELETE、OPTIONS');
header-[internal],line?? AppController::beforeFilter()-APP\Controller\AppController.php,第43行 调用用户函数-[内部],行?? CakeEventManager::dispatch()-CORE\Cake\Event\CakeEventManager.php,第243行 Controller::startupProcess()-CORE\Cake\Controller\Controller.php,第676行 Dispatcher::_invoke()-CORE\Cake\Routing\Dispatcher.php,第189行 Dispatcher::Dispatcher()-CORE\Cake\Routing\Dispatcher.php,第167行 ControllerTestCase::_testAction()-CORE\Cake\TestSuite\ControllerTestCase.php,第279行 ControllerTestCase::\uu call()-CORE\Cake\TestSuite\ControllerTestCase.php,第191行 CategoryProblemsControllerTest::testAction()-APP\Test\Case\Controller\CategoryProblemsControllerTest.php,第26行 CategoryProblemsControllerTest::testIndex()-APP\Test\Case\Controller\CategoryProblemsControllerTest.php,第26行 ReflectionMethod::invokeArgs()-[internal],第行?? PHPUnit\u Framework\u TestCase::runTest()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第976行 PHPUnit\u Framework\u TestCase::runBare()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第831行 PHPUnit\u Framework\u TestResult::run()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestResult.php,第648行 PHPUnit\u Framework\u TestCase::run()-C:\xampp\u 183\php\pear\PHPUnit\Framework\TestCase.php,第776行 CakeTestCase::run()-CORE\Cake\TestSuite\CakeTestCase.php,第82行 致命错误:对C中的非对象调用成员函数create():