在phpunit中,我想测试一个控制器。作为其中的一部分,我需要在调用新的Class()时返回一个模拟。
我试过了:
$mockEntity = $this->getMock( 'Vet', array( '__construct', 'setDoctrine', 'setContainer' ) );
$mockForm = $this->getMock( 'VetType', array( 'handleRequest', 'isValid', 'createView' ) );
$mockEntity->expects( $this->once() )->method( '__construct')->willReturn( $this->returnValue( $mockEntity ) );
还简单地说:
$mockEntity = $this->getMock( 'Vet', array( 'setDoctrine', 'setContainer' ) );
$mockForm = $this->getMock( 'VetType', array( 'handleRequest', 'isValid', 'createView' ) );
两者都返回“Vet”对象,而不是模拟。这是可能的phpUnit 4.0.20,还是我只需要添加一个getNewVet()函数?
这是一个Symfony2控制器