jenkins-bot has submitted this change and it was merged. Change subject: Use integers for WmfException codes ......................................................................
Use integers for WmfException codes Fixes tests that fail under PHP 5.6 / PHPUnit 4.2.6 TODO: constructor should allow you to use constants and lookup the type name Change-Id: I0cdfaac41ab113f8078a0180dd3ef677fcdb8552 --- M sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php M sites/all/modules/wmf_common/WmfException.php M sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php 3 files changed, 34 insertions(+), 14 deletions(-) Approvals: Awight: Looks good to me, approved jenkins-bot: Verified diff --git a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php index 24a4d31..cbf8df1 100644 --- a/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php +++ b/sites/all/modules/queue2civicrm/tests/phpunit/ProcessMessageTest.php @@ -65,7 +65,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode MISSING_PREDECESSOR + * @expectedExceptionCode WmfException::MISSING_PREDECESSOR */ public function testRecurringNoPredecessor() { $message = new RecurringPaymentMessage( array( @@ -81,7 +81,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode INVALID_RECURRING + * @expectedExceptionCode WmfException::INVALID_RECURRING */ public function testRecurringNoSubscrId() { $message = new RecurringPaymentMessage( array( @@ -119,7 +119,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode MISSING_PREDECESSOR + * @expectedExceptionCode WmfException::MISSING_PREDECESSOR */ public function testRefundNoPredecessor() { $refund_message = new RefundMessage(); @@ -129,7 +129,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode INVALID_MESSAGE + * @expectedExceptionCode WmfException::INVALID_MESSAGE */ public function testRefundMismatched() { $donation_message = new TransactionMessage( array( diff --git a/sites/all/modules/wmf_common/WmfException.php b/sites/all/modules/wmf_common/WmfException.php index b79d78c..68f6a3a 100644 --- a/sites/all/modules/wmf_common/WmfException.php +++ b/sites/all/modules/wmf_common/WmfException.php @@ -1,6 +1,24 @@ <?php class WmfException extends Exception { + const CIVI_CONFIG = 1; + const STOMP_BAD_CONNECTION = 2; + const INVALID_MESSAGE = 3; + const INVALID_RECURRING = 4; + const CIVI_REQ_FIELD = 5; + const IMPORT_CONTACT = 6; + const IMPORT_CONTRIB = 7; + const IMPORT_SUBSCRIPTION = 8; + const DUPLICATE_CONTRIBUTION = 9; + const GET_CONTRIBUTION = 10; + const PAYMENT_FAILED = 11; + const UNKNOWN = 12; + const UNSUBSCRIBE = 13; + const MISSING_PREDECESSOR = 14; + const FILE_NOT_FOUND = 15; + const INVALID_FILE_FORMAT = 16; + const fredge = 17; + //XXX shit we aren't using the 'rollback' attribute // and it's not correct in most of these cases static $error_types = array( @@ -63,19 +81,21 @@ ); var $extra; + var $type; function __construct( $type, $message, $extra = null ) { if ( !array_key_exists( $type, self::$error_types ) ) { $message .= ' -- ' . t( 'Warning, throwing a misspelled exception: "%type"', array( '%type' => $type ) ); $type = 'UNKNOWN'; } - $this->code = $type; + $this->type = $type; + $this->code = constant( 'WmfException::' . $type ); $this->extra = $extra; if ( is_array( $message ) ) { $message = implode( "\n", $message ); } - $this->message = "{$this->code} {$message}"; + $this->message = "{$this->type} {$message}"; if ( $extra ) { $this->message .= "\nSource: " . var_export( $extra, true ); @@ -88,13 +108,13 @@ watchdog( 'wmf_common', $escaped, NULL, WATCHDOG_ERROR ); } if ( function_exists('drush_set_error') && $this->isFatal() ) { - drush_set_error( $this->code, $this->message ); + drush_set_error( $this->type, $this->message ); } } function getErrorName() { - return $this->code; + return $this->type; } function isRollbackDb() @@ -138,7 +158,7 @@ protected function getErrorCharacteristic($property, $default) { - $info = self::$error_types[$this->code]; + $info = self::$error_types[$this->type]; if (array_key_exists($property, $info)) { return $info[$property]; } diff --git a/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php b/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php index 738d333..9d3fcf7 100644 --- a/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php +++ b/sites/all/modules/wmf_common/tests/phpunit/WmfTransactionTest.php @@ -69,7 +69,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode INVALID_MESSAGE + * @expectedExceptionCode WmfException::INVALID_MESSAGE */ function testInvalidEmptyId() { $transaction = WmfTransaction::from_unique_id( "" ); @@ -77,7 +77,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode INVALID_MESSAGE + * @expectedExceptionCode WmfException::INVALID_MESSAGE */ function testInvalidAlmostEmptyId() { $transaction = WmfTransaction::from_unique_id( 'RFD RECURRING' ); @@ -85,7 +85,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode INVALID_MESSAGE + * @expectedExceptionCode WmfException::INVALID_MESSAGE */ function testInvalidWhitespaceId() { $transaction = WmfTransaction::from_unique_id( 'RFD RECURRING ' ); @@ -93,7 +93,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode INVALID_MESSAGE + * @expectedExceptionCode WmfException::INVALID_MESSAGE */ function testInvalidExtraPartsId() { $transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY 123 1234 EXTRA_PART' ); @@ -101,7 +101,7 @@ /** * @expectedException WmfException - * @expectedExceptionCode INVALID_MESSAGE + * @expectedExceptionCode WmfException::INVALID_MESSAGE */ function testInvalidTimestampId() { $transaction = WmfTransaction::from_unique_id( 'TEST_GATEWAY 123 BAD_TIMESTAMP' ); -- To view, visit https://gerrit.wikimedia.org/r/211327 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I0cdfaac41ab113f8078a0180dd3ef677fcdb8552 Gerrit-PatchSet: 3 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits