我想用PHPUnit構建一個測試來測試我的Braintree鉤子。我有一個使用的數據提供程序下面這個測試用例:在爲Braintree構建PHPUnit測試時間接修改重載屬性webhook
/**
* @covers SubscriptionExpiredHook::processHook()
* @dataProvider dataProvider
*/
public function testProcessHook($subscriptionId)
{
$subscriptionExpiredHook = new SubscriptionExpiredHook($this->siteManager);
$notification = $this->getMockBuilder('Braintree\WebhookNotification')
->disableOriginalConstructor()
->getMock();
$notification->subscription->id = $subscriptionId;
$router = $this->getRouterMock();
$subscriptionExpiredHook->setSubscription(new Subscription($router));
$response = $subscriptionExpiredHook->processHook($notification);
$this->assertEquals(200, $response->getStatusCode());
}
public function dataProvider()
{
return [
[
'subscription_id' => 'CRM1872',
]
];
}
導致該問題的路線是這樣的:
$subscriptionId = $hook->subscription->id;
...這是我得到的錯誤,當我運行測試:
1) CRMPiccoBundle \測試\布倫特裏\魚鉤\ SubscriptionExpiredHookTest :: testProcessHook 與數據集#0( 'CRM1872')的重載間接修改財產Mock_WebhookNotification_e65192ec :: $認購沒有 效果
有沒有辦法,我可以設置訂閱ID,讓這個測試進行還是我看着它的錯誤的方式方法嗎?
謝謝,這是一個有用的答案。但是,我無法從我的測試中訪問Braintree API。當我調用'find'時,我得到以下錯誤 - Braintree \ Exception \ Configuration:Braintree \ Configuration :: merchantId需要設置(或者accessToken需要傳遞給Braintree \ Gateway)。我使用的是CometCult BraintreeBundle,我不知道PHPUnit是否無法訪問供應商包中的services.yml中的參數 - https://github.com/cometcult/CometCultBraintreeBundle/blob/master/Resources/config/services.yml #L7。整蠱一個測試... – crmpicco
我不熟悉CometCult BraintreeBundle,但該錯誤是一個相當普遍和直接的錯誤。如果您確定您的'merchantId','publicKey'和'privateKey'全部在您的環境中設置,那麼我會在Github或Stack Overflow上打開一個新問題,或發送電子郵件至[email protected] 。通常這些值是在'.env'文件中設置的,但我不知道如何管理您的配置。 – jellenberger
它看起來像'.env'等效於['app/config/config.yml'](https://github.com/cometcult/CometCultBraintreeBundle#configuration) – jellenberger