[NFC] declare thrown exceptions
authoreileen <emcnaughton@wikimedia.org>
Mon, 11 Nov 2019 03:38:46 +0000 (16:38 +1300)
committereileen <emcnaughton@wikimedia.org>
Mon, 11 Nov 2019 04:47:59 +0000 (17:47 +1300)
tests/phpunit/CiviTest/CiviUnitTestCase.php
tests/phpunit/api/v3/ContributionPageTest.php

index d5ca8938cee02e577df2c7cc9d0144e3f101762d..273c243b184b7202d37cdc6d5c6546882b56a5b1 100644 (file)
@@ -662,9 +662,13 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
   }
 
   /**
+   * Create a relationship type.
+   *
    * @param array $params
    *
-   * @return mixed
+   * @return int
+   *
+   * @throws \CRM_Core_Exception
    */
   public function relationshipTypeCreate($params = []) {
     $params = array_merge([
@@ -699,6 +703,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    * @param array $params
    *
    * @return mixed
+   * @throws \CRM_Core_Exception
    */
   public function paymentProcessorTypeCreate($params = NULL) {
     if (is_null($params)) {
@@ -980,6 +985,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase {
    * @param int $contributionId
    *
    * @return array|int
+   * @throws \CRM_Core_Exception
    */
   public function contributionDelete($contributionId) {
     $params = [
@@ -1866,7 +1872,7 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
    * @param int $delete
    * @param string $errorText
    *
-   * @throws Exception
+   * @throws CRM_Core_Exception
    */
   public function getAndCheck($params, $id, $entity, $delete = 1, $errorText = '') {
 
@@ -2971,6 +2977,10 @@ AND    ( TABLE_NAME LIKE 'civicrm_value_%' )
 
   /**
    * Enable Tax and Invoicing
+   *
+   * @param array $params
+   *
+   * @return \Civi\Core\SettingsBag
    */
   protected function enableTaxAndInvoicing($params = []) {
     // Enable component contribute setting
index 046c419fbf365b63e0d569c0513f591b66047302..6e75c6ee8382955c677dc61f2fc5ebc648b2c9ce 100644 (file)
@@ -56,14 +56,18 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    */
   protected $_ids = [];
 
-
   public $DBResetRequired = TRUE;
 
+  /**
+   * Setup for test.
+   *
+   * @throws \CRM_Core_Exception
+   */
   public function setUp() {
     parent::setUp();
     $this->contactIds[] = $this->individualCreate();
     $this->params = [
-      'title' => "Test Contribution Page",
+      'title' => 'Test Contribution Page',
       'financial_type_id' => 1,
       'currency' => 'NZD',
       'goal_amount' => $this->testAmount,
@@ -83,6 +87,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     ];
   }
 
+  /**
+   * Tear down after test.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
+   */
   public function tearDown() {
     foreach ($this->contactIds as $id) {
       $this->callAPISuccess('contact', 'delete', ['id' => $id]);
@@ -92,8 +102,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
   }
 
   /**
+   * Test creating a contribution page.
+   *
    * @param int $version
+   *
    * @dataProvider versionThreeAndFour
+   * @throws \CRM_Core_Exception
    */
   public function testCreateContributionPage($version) {
     $this->_apiversion = $version;
@@ -104,8 +118,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
   }
 
   /**
+   * Test getting a contribution page.
+   *
    * @param int $version
+   *
    * @dataProvider versionThreeAndFour
+   * @throws \CRM_Core_Exception
    */
   public function testGetBasicContributionPage($version) {
     $this->_apiversion = $version;
@@ -119,6 +137,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $this->assertEquals(1, $getResult['count']);
   }
 
+  /**
+   * Test get with amount as a parameter.
+   *
+   * @throws \CRM_Core_Exception
+   */
   public function testGetContributionPageByAmount() {
     $createResult = $this->callAPISuccess($this->_entity, 'create', $this->params);
     $this->id = $createResult['id'];
@@ -133,8 +156,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
   }
 
   /**
+   * Test page deletion.
+   *
    * @param int $version
+   *
    * @dataProvider versionThreeAndFour
+   * @throws \CRM_Core_Exception
    */
   public function testDeleteContributionPage($version) {
     $this->_apiversion = $version;
@@ -145,6 +172,11 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     $this->assertEquals(0, $checkDeleted['count']);
   }
 
+  /**
+   * Test getfields function.
+   *
+   * @throws \CRM_Core_Exception
+   */
   public function testGetFieldsContributionPage() {
     $result = $this->callAPISuccess($this->_entity, 'getfields', ['action' => 'create']);
     $this->assertEquals(12, $result['values']['start_date']['type']);
@@ -152,6 +184,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test form submission with basic price set.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmit() {
     $this->setUpContributionPage();
@@ -187,6 +221,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
   /**
    * Test form submission with billing first & last name where the contact does NOT
    * otherwise have one.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitNewBillingNameData() {
     $this->setUpContributionPage();
@@ -273,6 +309,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * Test process with instant payment when more than one configured for the page.
    *
    * CRM-16923
+   *
+   * @throws \CiviCRM_API3_Exception
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitRecurMultiProcessorInstantPayment() {
     $this->setUpContributionPage();
@@ -325,6 +364,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockNotSeparatePayment() {
     $this->setUpMembershipContributionPage();
@@ -336,10 +377,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'billing_middle_name' => 'Goat',
       'billing_last_name' => 'Gruff',
       'selectMembership' => $this->_ids['membership_type'],
-
     ];
 
-    $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
+    $this->callAPIAndDocument('ContributionPage', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
     $contribution = $this->callAPISuccess('contribution', 'getsingle', ['contribution_page_id' => $this->_ids['contribution_page']]);
     $membershipPayment = $this->callAPISuccess('membership_payment', 'getsingle', ['contribution_id' => $contribution['id']]);
     $this->callAPISuccessGetSingle('LineItem', ['contribution_id' => $contribution['id'], 'entity_id' => $membershipPayment['id']]);
@@ -395,6 +435,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockNotSeparatePaymentWithEmail() {
     $mut = new CiviMailUtils($this, TRUE);
@@ -430,6 +472,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \Exception
    */
   public function testSubmitMembershipBlockNotSeparatePaymentZeroDollarsWithEmail() {
     $mut = new CiviMailUtils($this, TRUE);
@@ -468,6 +512,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a pay later abnd check line item in mails.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockIsSeparatePaymentPayLaterWithEmail() {
     $mut = new CiviMailUtils($this, TRUE);
@@ -496,6 +542,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockIsSeparatePayment() {
     $this->setUpMembershipContributionPage(TRUE);
@@ -523,6 +571,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockIsSeparatePaymentWithPayLater() {
     $this->setUpMembershipContributionPage(TRUE);
@@ -560,6 +610,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockIsSeparatePaymentWithEmail() {
     $mut = new CiviMailUtils($this, TRUE);
@@ -607,6 +659,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockIsSeparatePaymentZeroDollarsPayLaterWithEmail() {
     $mut = new CiviMailUtils($this, TRUE);
@@ -644,6 +698,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipBlockTwoTypesIsSeparatePayment() {
     $this->_ids['membership_type'] = [$this->membershipTypeCreate(['minimum_fee' => 6])];
@@ -736,6 +792,9 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * @param string $thousandSeparator
    *   punctuation used to refer to thousands.
    *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
+   *
    * @dataProvider getThousandSeparators
    */
   public function testSubmitMembershipBlockIsSeparatePaymentPaymentProcessorNowChargesCorrectAmounts($thousandSeparator) {
@@ -765,8 +824,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     // set custom hook
     $this->hookClass->setHook('civicrm_alterPaymentProcessorParams', [$this, 'hook_civicrm_alterPaymentProcessorParams']);
 
-    $this->callAPISuccess('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
-    $contributions = $this->callAPISuccess('contribution', 'get', [
+    $this->callAPISuccess('ContributionPage', 'submit', $submitParams);
+    $this->callAPISuccess('contribution', 'get', [
       'contribution_page_id' => $this->_ids['contribution_page'],
       'contribution_status_id' => 1,
     ]);
@@ -809,6 +868,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * Test that when a transaction fails the pending contribution remains.
    *
    * An activity should also be created. CRM-16417.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitPaymentProcessorFailure() {
     $this->setUpContributionPage();
@@ -847,6 +908,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * processor (IATS style - denoted by returning trxn_id)
    * - the first creates a new membership, completed contribution, in progress recurring. Check these
    * - create another - end date should be extended
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPaymentYear() {
     $this->doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment(['duration_unit' => 'year', 'recur_frequency_unit' => 'year']);
@@ -881,7 +944,6 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * @param array $params
    *
    * @throws \CRM_Core_Exception
-   * @throws \Exception
    */
   public function doSubmitMembershipPriceSetPaymentPaymentProcessorRecurInstantPayment($params = []) {
     $this->params['is_recur'] = 1;
@@ -970,6 +1032,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * processor (IATS style - denoted by returning trxn_id)
    * - the first creates a new membership, completed contribution, in progress recurring. Check these
    * - create another - end date should be extended
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipComplexNonPriceSetPaymentPaymentProcessorRecurInstantPayment() {
     $this->params['is_recur'] = 1;
@@ -1054,6 +1118,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * processor (IATS style - denoted by returning trxn_id)
    * - the first creates a new membership, completed contribution, in progress recurring. Check these
    * - create another - end date should be extended
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipComplexPriceSetPaymentPaymentProcessorRecurInstantPayment() {
     $this->params['is_recur'] = 1;
@@ -1135,6 +1201,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Extend the price set with a second organisation's membership.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function addSecondOrganizationMembershipToPriceSet() {
     $organization2ID = $this->organizationCreate();
@@ -1188,6 +1256,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * processor (IATS style - denoted by returning trxn_id)
    * - the first creates a new membership, completed contribution, in progress recurring. Check these
    * - create another - end date should be extended
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipPriceSetPaymentPaymentProcessorSeparatePaymentRecurInstantPayment() {
 
@@ -1215,7 +1285,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'frequency_unit' => 'month',
     ];
 
-    $this->callAPIAndDocument('contribution_page', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
+    $this->callAPIAndDocument('ContributionPage', 'submit', $submitParams, __FUNCTION__, __FILE__, 'submit contribution page', NULL);
     $contribution = $this->callAPISuccess('contribution', 'get', [
       'contribution_page_id' => $this->_ids['contribution_page'],
       'contribution_status_id' => 1,
@@ -1235,6 +1305,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * - the first creates a pending membership, pending contribution, penging recurring. Check these
    * - complete the transaction
    * - create another - end date should NOT be extended
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipPriceSetPaymentPaymentProcessorRecurDelayed() {
     $this->params['is_recur'] = 1;
@@ -1325,6 +1397,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test non-recur contribution with membership payment
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMembershipIsSeparatePaymentNotRecur() {
     //Create recur contribution page.
@@ -1359,9 +1433,12 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Set up membership contribution page.
+   *
    * @param bool $isSeparatePayment
    * @param bool $isRecur
    * @param array $membershipTypeParams Parameters to pass to membershiptype.create API
+   *
+   * @throws \CRM_Core_Exception
    */
   public function setUpMembershipContributionPage($isSeparatePayment = FALSE, $isRecur = FALSE, $membershipTypeParams = []) {
     $this->setUpMembershipBlockPriceSet($membershipTypeParams);
@@ -1397,6 +1474,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * The default data set does not include a complete default membership price set - not quite sure why.
    *
    * This function ensures it exists & populates $this->_ids with it's data
+   *
+   * @throws \CRM_Core_Exception
    */
   public function setUpMembershipBlockPriceSet($membershipTypeParams = []) {
     $this->_ids['price_set'][] = $this->callAPISuccess('price_set', 'getvalue', [
@@ -1473,6 +1552,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Add text field other amount to the price set.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function addOtherAmountFieldToMembershipPriceSet() {
     $this->_ids['price_field']['other_amount'] = $this->callAPISuccess('price_field', 'create', [
@@ -1494,7 +1575,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Help function to set up contribution page with some defaults.
+   *
    * @param bool $isRecur
+   *
+   * @throws \CRM_Core_Exception
    */
   public function setUpContributionPage($isRecur = FALSE) {
     if ($isRecur) {
@@ -1552,6 +1636,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
   /**
    * Helper function to set up contribution page which can be used to purchase a
    * membership type for different intervals.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function setUpMultiIntervalMembershipContributionPage() {
     $this->setupPaymentProcessor();
@@ -1564,7 +1650,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
       'duration_unit' => 'month',
     ]);
 
-    $priceSet = civicrm_api3('PriceSet', 'create', [
+    $priceSet = $this->callAPISuccess('PriceSet', 'create', [
       'is_quick_config' => 0,
       'extends' => 'CiviMember',
       'financial_type_id' => 'Member Dues',
@@ -1616,6 +1702,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Test submit with a membership block in place.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitMultiIntervalMembershipContributionPage() {
     $this->setUpMultiIntervalMembershipContributionPage();
@@ -1651,22 +1739,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
     // put stuff here that should happen before all tests in this unit
   }
 
-  /**
-   * @throws \Exception
-   */
-  public static function tearDownAfterClass() {
-    $tablesToTruncate = [
-      'civicrm_contact',
-      'civicrm_financial_type',
-      'civicrm_contribution',
-      'civicrm_contribution_page',
-    ];
-    $unitTest = new CiviUnitTestCase();
-    $unitTest->quickCleanup($tablesToTruncate);
-  }
-
   /**
    * Create a payment processor instance.
+   *
+   * @throws \CRM_Core_Exception
    */
   protected function setupPaymentProcessor() {
     $this->params['payment_processor_id'] = $this->_ids['payment_processor'] = $this->paymentProcessorCreate([
@@ -1681,6 +1757,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * Test submit recurring pledge.
    *
    * - we process 1 pledge with a future start date. A recur contribution and the pledge should be created with first payment date in the future.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitPledgePaymentPaymentProcessorRecurFuturePayment() {
     $this->params['adjust_recur_start_date'] = TRUE;
@@ -1749,6 +1827,8 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    * Test submit pledge payment.
    *
    * - test submitting a pledge payment using contribution form.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitPledgePayment() {
     $this->testSubmitPledgePaymentPaymentProcessorRecurFuturePayment();
@@ -1801,6 +1881,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    *   punctuation used to refer to thousands.
    *
    * @dataProvider getThousandSeparators
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitContributionPageWithPriceSet($thousandSeparator) {
     $this->setCurrencySeparators($thousandSeparator);
@@ -1836,7 +1917,10 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
 
   /**
    * Function to add additional price fields to priceset.
+   *
    * @param array $params
+   *
+   * @throws \CRM_Core_Exception
    */
   public function addPriceFields(&$params) {
     $priceSetID = reset($this->_ids['price_set']);
@@ -1872,6 +1956,7 @@ class api_v3_ContributionPageTest extends CiviUnitTestCase {
    *   punctuation used to refer to thousands.
    *
    * @dataProvider getThousandSeparators
+   * @throws \CRM_Core_Exception
    */
   public function testSubmitContributionPageWithPriceSetQuantity($thousandSeparator) {
     $this->setCurrencySeparators($thousandSeparator);