PHPUnit Mock Objects and Static Methods

后端 未结 7 1327
梦谈多话
梦谈多话 2020-11-27 18:02

I am looking for the best way to go about testing the following static method (specifically using a Doctrine Model):

class Model_User extends Doctrine_Record         


        
相关标签:
7条回答
  • 2020-11-27 19:05

    Testing static methods is generally considered as a bit hard (as you probably already noticed), especially before PHP 5.3.

    Could you not modify your code to not use static a method ? I don't really see why you're using a static method here, in fact ; this could probably be re-written to some non-static code, could it not ?


    For instance, could something like this not do the trick :

    class Model_User extends Doctrine_Record
    {
        public function saveFromArray($userData)
        {
            $this->fromArray($userData);
            $this->save();
        }
    }
    

    Not sure what you'll be testing ; but, at least, no static method anymore...

    0 讨论(0)
提交回复
热议问题