致命错误:当作为CakeTestCase运行时,在2106行的... / model.php中的非对象上调用成员函数trigger()

时间:2011-03-02 03:12:44

标签: unit-testing cakephp

我是PHP的新手,CakePHP和1.3的CakePHP单元测试框架。

我创建了一个模型的简单测试用例并遇到了这个错误:

  

致命错误:调用成员函数   触发器()在非对象中   /Users/calvinc/Sites/lhasa/web/cake/libs/model/model.php   在2106行

我注意到model.php中的2106行如下:

  if ($query['callbacks'] === true || $query['callbacks'] === 'before') {
      $return = $this->Behaviors->trigger($this, 'beforeFind', array($query), array(

我猜测没有设置行为。这是什么原因?

这是Login对象的转储。

[Wed Mar 02 11:06:26 2011] [错误] [client 127.0.0.1]登录对象 (     [actsAs] =>排列         (             [0] =>中容纳         )

[utcOffset] => 8
[useDbConfig] => default
[useTable] => 
[displayField] => 
[id] => 
[data] => Array
    (
    )

[table] => 
[primaryKey] => 
[_schema] => 
[validationErrors] => Array
    (
    )

[tablePrefix] => 
[name] => 
[alias] => 
[tableToModel] => Array
    (
    )

[logTransactions] => 
[cacheQueries] => 
[belongsTo] => Array
    (
    )

[hasOne] => Array
    (
    )

[hasMany] => Array
    (
    )

[hasAndBelongsToMany] => Array
    (
    )

[Behaviors] => 
[whitelist] => Array
    (
    )

[cacheSources] => 1
[findQueryType] => 
[recursive] => 1
[order] => 
[virtualFields] => Array
    (
    )

[__associationKeys] => Array
    (
        [belongsTo] => Array
            (
                [0] => className
                [1] => foreignKey
                [2] => conditions
                [3] => fields
                [4] => order
                [5] => counterCache
            )

        [hasOne] => Array
            (
                [0] => className
                [1] => foreignKey
                [2] => conditions
                [3] => fields
                [4] => order
                [5] => dependent
            )

        [hasMany] => Array
            (
                [0] => className
                [1] => foreignKey
                [2] => conditions
                [3] => fields
                [4] => order
                [5] => limit
                [6] => offset
                [7] => dependent
                [8] => exclusive
                [9] => finderQuery
                [10] => counterQuery
            )

        [hasAndBelongsToMany] => Array
            (
                [0] => className
                [1] => joinTable
                [2] => with
                [3] => foreignKey
                [4] => associationForeignKey
                [5] => conditions
                [6] => fields
                [7] => order
                [8] => limit
                [9] => offset
                [10] => unique
                [11] => finderQuery
                [12] => deleteQuery
                [13] => insertQuery
            )

    )

[__associations] => Array
    (
        [0] => belongsTo
        [1] => hasOne
        [2] => hasMany
        [3] => hasAndBelongsToMany
    )

[__backAssociation] => Array
    (
    )

[__insertID] => 
[__numRows] => 
[__affectedRows] => 
[_findMethods] => Array
    (
        [all] => 1
        [first] => 1
        [count] => 1
        [neighbors] => 1
        [list] => 1
        [threaded] => 1
    )

1 个答案:

答案 0 :(得分:2)

我认为你的问题......是我的问题。 所以..我的问题是我的模型中有一个方法,我的模型名称相同。

class Ranking extends AppModel {
   function ranking($a)....
}

这使PHP将该函数解释为构造函数,因此未调用AppModel构造函数。我们的模型确实没有正确的数据。