我嘗試測試時無法爲內部方法設定值。這裏我寫了一個樣本班。我爲同一個類創建了模擬對象,但不起作用。php單位的內部方法的設定值
class A
{
public function OneTest()
{
if($this->TwoTest()){
return true;
}
}
public function TwoTest()
{
// return somethings
}
}
我是新的phpunit測試寫作。如果有一位專家幫助我,那對我有好處。我想測試這種方法。我曾嘗試過:
class ATest extends \PHPUnit_Framework_TestCase
{
public function testOne()
{
$helper = new testOne();
// trying to set TwoTest() method value but does not effect.
$mock = $this->createMock(A::class);
$mock->method("TwoTest")
->willReturn(true);
$this->assertTrue($helper->OneTest();
}
}
其實我不知道如何使用我的模擬方法結果。我在twoTest方法中的實際實現包含一些與數據庫相關的代碼。我不想在測試時間運行db代碼。