在CakePHP中模拟受保护的方法时出错

时间:2013-01-31 07:26:41

标签: cakephp phpunit

我在CakePHP 2.2.5中模拟受保护的方法时遇到困难,当我将方法更改为public时一切正常但是一旦受到保护我就会收到以下错误:

PDOException SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第1行的“is_uploaded_file”附近使用正确的语法

我的模型看起来像这样:

<?php
class Contact extends AppModel {
    public $name = 'Contact';

    protected function is_uploaded_file($tmp_name) {
        return is_uploaded_file($tmp_name);
    }
}

我的测试看起来像这样:

<?php
App::uses('Contact', 'Model');
class ContactTest extends CakeTestCase {
    public function setUp() {
        parent::setUp();
        $this->Contact = ClassRegistry::init('Contact');
    }

    public function testStub() {
        $stub = $this->getMock('Contact',array('is_uploaded_file'));

        // Configure the stub.
        $stub->expects($this->any())
            ->method('is_uploaded_file')
            ->will($this->returnValue(TRUE));

        $this->assertEquals(TRUE, $stub->is_uploaded_file('tmp'));
    }
}

有什么想法吗?非常感谢。

0 个答案:

没有答案
相关问题