PHPUnit:调用未定义的方法

时间:2013-11-16 18:57:53

标签: phpunit

我想运行简单的播放器插入测试。

我的代码是这样的:

class Player{
    public $id;
    public $name;
}
class PlayerDAO{
   //db stuff
   .....
   privatefunction input($player){
      $player->id = mysql_real_escape_string($player->id);
      $player->name = mysql_real_escape_string($player->name);
      return $player;
   }
   public function insert($player){
      $player = $this->input($player);
      mysql_query("INSERT INTO player (name) VALUES ('.$player->name.')");
   }
   public function countPlayers(){
      $r = mysql_query("SELECT * FROM player");

      return mysql_num_rows($r);
   }
}
 //Test class
class PlayerTest extends PHPUnit_Framework_TestCase {
   public function testInsert(){
   $player = new Player();
   $player->name = 'Test name';

   $count1 = PlayerDAO::countPlayers();
   PlayerDAO::insert($player);
   $count2 = PlayerDAO::countPlayers();
   $this->assertEquals(($count2-$count1), 1);

   }
}

如果我运行测试,我会收到错误消息:致命错误:在... PlayerTest.php中调用未定义的方法PlayerTest :: input()。如果我从insert()方法中删除方法input(),则错误消息消失。

0 个答案:

没有答案