PHPUnit Mock Objects and Static Methods

后端 未结 7 1473
梦谈多话
梦谈多话 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 18:42

    Another possible approach is with the Moka library:

    $modelClass = Moka::mockClass('Model_User', [ 
        'fromArray' => null, 
        'save' => null
    ]);
    
    $modelClass::create('DATA');
    $this->assertEquals(['DATA'], $modelClass::$moka->report('fromArray')[0]);
    $this->assertEquals(1, sizeof($modelClass::$moka->report('save')));
    

提交回复
热议问题