Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/375086 )
Change subject: Set dummy response codes statically, round 2 ...................................................................... Set dummy response codes statically, round 2 This time, don't introduce another dependency on Mediawiki Change-Id: I7d6321a3ef6767d50efe7173f1ad8c54efee2ab2 --- M tests/phpunit/Adapter/AstroPay/AstroPayTest.php M tests/phpunit/Adapter/GatewayAdapterTest.php M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php M tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php M tests/phpunit/Adapter/GlobalCollect/RecurringTest.php M tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php M tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php M tests/phpunit/Adapter/Ingenico/IngenicoTest.php M tests/phpunit/Adapter/Ingenico/RecurringTest.php M tests/phpunit/Adapter/PayPal/PayPalApiTest.php M tests/phpunit/Adapter/PayPal/PayPalExpressTest.php M tests/phpunit/DonationInterfaceApiTestCase.php M tests/phpunit/DonationInterfaceTestCase.php M tests/phpunit/LoggingTest.php M tests/phpunit/MustacheFormTest.php M tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php M tests/phpunit/includes/test_gateway/test.adapter.php 18 files changed, 93 insertions(+), 90 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DonationInterface refs/changes/86/375086/1 diff --git a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php index c30a7f6..098ca24 100644 --- a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php +++ b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php @@ -132,7 +132,7 @@ $init = $this->getDonorTestData( 'BR' ); $this->setLanguage( $init['language'] ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'notJson' ); + $gateway::setDummyGatewayResponseCode( 'notJson' ); $gateway->do_transaction( 'NewInvoice' ); @@ -148,7 +148,7 @@ $init = $this->getDonorTestData( 'BR' ); $this->setLanguage( $init['language'] ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '1' ); + $gateway::setDummyGatewayResponseCode( '1' ); $gateway->do_transaction( 'NewInvoice' ); @@ -203,7 +203,7 @@ $init = $this->getDonorTestData( 'BR' ); $this->setLanguage( $init['language'] ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '1' ); + $gateway::setDummyGatewayResponseCode( '1' ); $result = $gateway->doPayment(); @@ -227,7 +227,7 @@ $this->setLanguage( $init['language'] ); $init['payment_method'] = 'cc'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'limit_exceeded' ); + $gateway::setDummyGatewayResponseCode( 'limit_exceeded' ); $result = $gateway->doPayment(); $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); @@ -245,7 +245,7 @@ $this->setLanguage( $init['language'] ); $init['payment_method'] = 'cc'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'fiscal_number' ); + $gateway::setDummyGatewayResponseCode( 'fiscal_number' ); $result = $gateway->doPayment(); $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); @@ -263,7 +263,7 @@ $this->setLanguage( $init['language'] ); $init['payment_method'] = 'cc'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'user_unauthorized' ); + $gateway::setDummyGatewayResponseCode( 'user_unauthorized' ); $result = $gateway->doPayment(); $this->assertTrue( $result->isFailed() ); @@ -277,7 +277,7 @@ $this->setLanguage( $init['language'] ); $init['payment_method'] = 'cc'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'could_not_register' ); + $gateway::setDummyGatewayResponseCode( 'could_not_register' ); $result = $gateway->doPayment(); $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); @@ -295,7 +295,7 @@ $this->setLanguage( $init['language'] ); $init['payment_method'] = 'cc'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'could_not_make_deposit' ); + $gateway::setDummyGatewayResponseCode( 'could_not_make_deposit' ); $result = $gateway->doPayment(); $this->assertTrue( $result->getRefresh(), 'PaymentResult should be a refresh' ); @@ -346,7 +346,7 @@ $this->setUpRequest( $init, $session ); $gateway = new TestingAstroPayAdapter(); - $gateway->setDummyGatewayResponseCode( 'badsig' ); + TestingAstroPayAdapter::setDummyGatewayResponseCode( 'badsig' ); $gateway->do_transaction( 'PaymentStatus' ); $results = $gateway->getTransactionData(); @@ -515,7 +515,7 @@ $init = $this->getDonorTestData( 'BR' ); $firstRequest = $this->setUpRequest( $init ); $firstAttempt = new TestingAstroPayAdapter(); - $firstAttempt->setDummyGatewayResponseCode( '1' ); + TestingAstroPayAdapter::setDummyGatewayResponseCode( '1' ); $firstAttempt->doPayment(); @@ -538,7 +538,7 @@ function testNewInvoiceOrderIdRetry() { $init = $this->getDonorTestData( 'BR' ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'collision' ); + $gateway::setDummyGatewayResponseCode( 'collision' ); $gateway->doPayment(); diff --git a/tests/phpunit/Adapter/GatewayAdapterTest.php b/tests/phpunit/Adapter/GatewayAdapterTest.php index 230d916..672d56a 100644 --- a/tests/phpunit/Adapter/GatewayAdapterTest.php +++ b/tests/phpunit/Adapter/GatewayAdapterTest.php @@ -85,7 +85,7 @@ $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway ); - $this->resetAllEnv(); + self::resetAllEnv(); $gateway = $this->getFreshGatewayObject( $options = array() ); $this->assertInstanceOf( TESTS_ADAPTER_DEFAULT, $gateway, "Having trouble constructing a blank adapter." ); } diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php index 43816e1..2b1c908 100644 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php @@ -142,7 +142,7 @@ $init['contribution_tracking_id'] = mt_rand(); $gateway->loadDataAndReInit( $init ); - $gateway->setDummyGatewayResponseCode( $code ); + $gateway::setDummyGatewayResponseCode( $code ); $result = $gateway->do_transaction( 'Confirm_CreditCard' ); $this->assertEquals( 1, count( $gateway->curled ), "Gateway kept trying even with response code $code! Mastercard could fine us a thousand bucks for that!" ); $this->assertEquals( false, $result->getCommunicationStatus(), "Error code $code should mean status of do_transaction is false" ); @@ -178,7 +178,7 @@ $init['payment_method'] = 'cc'; $gateway->loadDataAndReInit( $init ); - $gateway->setDummyGatewayResponseCode( '600_badCvv' ); + $gateway::setDummyGatewayResponseCode( '600_badCvv' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $action = $gateway->getValidationAction(); diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php index a892c08..af5653d 100644 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanRectifierTest.php @@ -71,7 +71,7 @@ $rectifier = new GlobalCollectOrphanRectifier(); $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_PENDING ); + TestingGlobalCollectOrphanAdapter::setDummyGatewayResponseCode( self::STATUS_PENDING ); $rectifier->processOrphans(); $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( @@ -92,7 +92,7 @@ $rectifier = new GlobalCollectOrphanRectifier(); $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_PENDING_POKE ); + TestingGlobalCollectOrphanAdapter::setDummyGatewayResponseCode( self::STATUS_PENDING_POKE ); $rectifier->processOrphans(); $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( @@ -117,7 +117,7 @@ $rectifier = new GlobalCollectOrphanRectifier(); $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_COMPLETE ); + TestingGlobalCollectOrphanAdapter::setDummyGatewayResponseCode( self::STATUS_COMPLETE ); $rectifier->processOrphans(); $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php index a5551ad..fde5a62 100644 --- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php @@ -188,7 +188,7 @@ $this->setUpRequest( array( 'CVVRESULT' => 'M' ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '25' ); + $gateway::setDummyGatewayResponseCode( '25' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $action = $gateway->getValidationAction(); @@ -216,7 +216,7 @@ $init['payment_method'] = 'cc'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '600_badCvv' ); + $gateway::setDummyGatewayResponseCode( '600_badCvv' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $action = $gateway->getValidationAction(); @@ -415,13 +415,13 @@ //this should not throw any payments errors: Just an invalid card. $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '430285' ); + $gateway::setDummyGatewayResponseCode( '430285' ); $gateway->do_transaction( 'GET_ORDERSTATUS' ); $this->verifyNoLogErrors(); //Now test one we want to throw a payments error $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '21000050' ); + $gateway::setDummyGatewayResponseCode( '21000050' ); $gateway->do_transaction( 'GET_ORDERSTATUS' ); $loglines = self::getLogMatches( LogLevel::ERROR, '/Investigation required!/' ); $this->assertNotEmpty( $loglines, 'GC Error 21000050 is not generating the expected payments log error' ); @@ -431,7 +431,7 @@ //Most irritating version of 20001000 - They failed to enter an expiration date on GC's form. This should log some specific info, but not an error. $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '20001000-expiry' ); + $gateway::setDummyGatewayResponseCode( '20001000-expiry' ); $gateway->do_transaction( 'GET_ORDERSTATUS' ); $this->verifyNoLogErrors(); $loglines = self::getLogMatches( LogLevel::INFO, '/processResponse:.*EXPIRYDATE/' ); @@ -455,7 +455,7 @@ //Toxic card should not retry, even if there's an order id collision $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( $code ); + $gateway::setDummyGatewayResponseCode( $code ); $gateway->do_transaction( 'Confirm_CreditCard' ); $this->assertEquals( 1, count( $gateway->curled ), "Gateway kept trying even with response code $code! Mastercard could fine us a thousand bucks for that!" ); } @@ -494,7 +494,7 @@ ) ); $gateway = new TestingGlobalCollectAdapter(); - $gateway->setDummyGatewayResponseCode( 'Exception' ); + TestingGlobalCollectAdapter::setDummyGatewayResponseCode( 'Exception' ); try { $gateway->do_transaction( 'INSERT_ORDERWITHPAYMENT' ); } @@ -525,7 +525,7 @@ ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( $code ); + $gateway::setDummyGatewayResponseCode( $code ); $exposed = TestingAccessWrapper::newFromObject( $gateway ); $start_id = $exposed->getData_Staged( 'order_id' ); $gateway->do_transaction( 'Confirm_CreditCard' ); @@ -566,7 +566,7 @@ $gateway = $this->getFreshGatewayObject( $init ); $orig_id = $gateway->getData_Unstaged_Escaped( 'order_id' ); - $gateway->setDummyGatewayResponseCode( function ( $gateway ) use ( $orig_id ) { + $gateway::setDummyGatewayResponseCode( function ( $gateway ) use ( $orig_id ) { if ( $gateway->getData_Unstaged_Escaped( 'order_id' ) === $orig_id ) { return 'duplicate'; } else { @@ -593,7 +593,7 @@ $init['ffname'] = 'cc-vmad'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '11000400' ); + $gateway::setDummyGatewayResponseCode( '11000400' ); $gateway->do_transaction( 'SET_PAYMENT' ); $loglines = self::getLogMatches( LogLevel::INFO, '/Repeating transaction for timeout/' ); $this->assertNotEmpty( $loglines, "Log does not say we retried for timeout." ); @@ -627,7 +627,7 @@ $session['Donor'] = $init; $this->setUpRequest( $init, $session ); $gateway = $this->getFreshGatewayObject( array() ); - $gateway->setDummyGatewayResponseCode( '430285' ); // invalid card + $gateway::setDummyGatewayResponseCode( '430285' ); // invalid card $result = $gateway->processDonorReturn( array( 'REF' => $init['order_id'], 'CVVRESULT' => 'M', diff --git a/tests/phpunit/Adapter/GlobalCollect/RecurringTest.php b/tests/phpunit/Adapter/GlobalCollect/RecurringTest.php index 64b7923..293c49d 100644 --- a/tests/phpunit/Adapter/GlobalCollect/RecurringTest.php +++ b/tests/phpunit/Adapter/GlobalCollect/RecurringTest.php @@ -58,7 +58,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-OK' ); + $gateway::setDummyGatewayResponseCode( 'recurring-OK' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); @@ -81,7 +81,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-declined' ); + $gateway::setDummyGatewayResponseCode( 'recurring-declined' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); @@ -107,7 +107,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-timeout' ); + $gateway::setDummyGatewayResponseCode( 'recurring-timeout' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); @@ -132,7 +132,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-resume' ); + $gateway::setDummyGatewayResponseCode( 'recurring-resume' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php index 582925b..3f7735b 100644 --- a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php +++ b/tests/phpunit/Adapter/Ingenico/IngenicoOrphanAdapterTest.php @@ -140,7 +140,7 @@ $init['contribution_tracking_id'] = mt_rand(); $gateway->loadDataAndReInit( $init ); - $gateway->setDummyGatewayResponseCode( $code ); + $gateway::setDummyGatewayResponseCode( $code ); $result = $gateway->do_transaction( 'Confirm_CreditCard' ); $this->assertEquals( 1, count( $gateway->curled ), "Gateway kept trying even with response code $code! Mastercard could fine us a thousand bucks for that!" ); $this->assertEquals( false, $result->getCommunicationStatus(), "Error code $code should mean status of do_transaction is false" ); @@ -177,7 +177,7 @@ $init['payment_method'] = 'cc'; $gateway->loadDataAndReInit( $init ); - $gateway->setDummyGatewayResponseCode( '600_badCvv' ); + $gateway::setDummyGatewayResponseCode( '600_badCvv' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $action = $gateway->getValidationAction(); diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php index 4926c49..4ee20f3 100644 --- a/tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php +++ b/tests/phpunit/Adapter/Ingenico/IngenicoOrphanRectifierTest.php @@ -76,7 +76,7 @@ $rectifier = new IngenicoOrphanRectifier(); $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_PENDING ); + $this->gateway::setDummyGatewayResponseCode( self::STATUS_PENDING ); $rectifier->processOrphans(); $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( @@ -97,7 +97,7 @@ $rectifier = new IngenicoOrphanRectifier(); $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_PENDING_POKE ); + $this->gateway::setDummyGatewayResponseCode( self::STATUS_PENDING_POKE ); $rectifier->processOrphans(); $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( @@ -122,7 +122,7 @@ $rectifier = new IngenicoOrphanRectifier(); $this->gateway = $rectifier->getAdapter(); - $this->gateway->setDummyGatewayResponseCode( self::STATUS_COMPLETE ); + $this->gateway::setDummyGatewayResponseCode( self::STATUS_COMPLETE ); $rectifier->processOrphans(); $fetched = $this->pendingDb->fetchMessageByGatewayOrderId( diff --git a/tests/phpunit/Adapter/Ingenico/IngenicoTest.php b/tests/phpunit/Adapter/Ingenico/IngenicoTest.php index dcddcae..23ccd98 100644 --- a/tests/phpunit/Adapter/Ingenico/IngenicoTest.php +++ b/tests/phpunit/Adapter/Ingenico/IngenicoTest.php @@ -128,7 +128,7 @@ $this->setUpRequest( array( 'CVVRESULT' => 'M' ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '25' ); + $gateway::setDummyGatewayResponseCode( '25' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $action = $gateway->getValidationAction(); @@ -157,7 +157,7 @@ $init['payment_method'] = 'cc'; $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '600_badCvv' ); + $gateway::setDummyGatewayResponseCode( '600_badCvv' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $action = $gateway->getValidationAction(); @@ -284,13 +284,13 @@ //this should not throw any payments errors: Just an invalid card. $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '430285' ); + $gateway::setDummyGatewayResponseCode( '430285' ); $gateway->do_transaction( 'GET_ORDERSTATUS' ); $this->verifyNoLogErrors(); //Now test one we want to throw a payments error $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '21000050' ); + $gateway::setDummyGatewayResponseCode( '21000050' ); $gateway->do_transaction( 'GET_ORDERSTATUS' ); $loglines = $this->getLogMatches( LogLevel::ERROR, '/Investigation required!/' ); $this->assertNotEmpty( $loglines, 'GC Error 21000050 is not generating the expected payments log error' ); @@ -300,7 +300,7 @@ //Most irritating version of 20001000 - They failed to enter an expiration date on GC's form. This should log some specific info, but not an error. $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '20001000-expiry' ); + $gateway::setDummyGatewayResponseCode( '20001000-expiry' ); $gateway->do_transaction( 'GET_ORDERSTATUS' ); $this->verifyNoLogErrors(); $loglines = $this->getLogMatches( LogLevel::INFO, '/processResponse:.*EXPIRYDATE/' ); @@ -325,7 +325,7 @@ //Toxic card should not retry, even if there's an order id collision $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( $code ); + $gateway::setDummyGatewayResponseCode( $code ); $gateway->do_transaction( 'Confirm_CreditCard' ); $this->assertEquals( 1, count( $gateway->curled ), "Gateway kept trying even with response code $code! Mastercard could fine us a thousand bucks for that!" ); } @@ -408,7 +408,7 @@ ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( $code ); + $gateway::setDummyGatewayResponseCode( $code ); $exposed = TestingAccessWrapper::newFromObject( $gateway ); $start_id = $exposed->getData_Staged( 'order_id' ); $gateway->do_transaction( 'Confirm_CreditCard' ); @@ -466,7 +466,7 @@ $session['Donor'] = $init; $this->setUpRequest( $init, $session ); $gateway = $this->getFreshGatewayObject( array() ); - $gateway->setDummyGatewayResponseCode( '430285' ); // invalid card + $gateway::setDummyGatewayResponseCode( '430285' ); // invalid card $result = $gateway->processDonorReturn( array( 'REF' => $init['order_id'], 'CVVRESULT' => 'M', diff --git a/tests/phpunit/Adapter/Ingenico/RecurringTest.php b/tests/phpunit/Adapter/Ingenico/RecurringTest.php index 20e2bf5..b3e4274 100644 --- a/tests/phpunit/Adapter/Ingenico/RecurringTest.php +++ b/tests/phpunit/Adapter/Ingenico/RecurringTest.php @@ -45,7 +45,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-OK' ); + $gateway::setDummyGatewayResponseCode( 'recurring-OK' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); @@ -68,7 +68,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-declined' ); + $gateway::setDummyGatewayResponseCode( 'recurring-declined' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); @@ -100,7 +100,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-timeout' ); + $gateway::setDummyGatewayResponseCode( 'recurring-timeout' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); @@ -125,7 +125,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'recurring-resume' ); + $gateway::setDummyGatewayResponseCode( 'recurring-resume' ); $result = $gateway->do_transaction( 'Recurring_Charge' ); diff --git a/tests/phpunit/Adapter/PayPal/PayPalApiTest.php b/tests/phpunit/Adapter/PayPal/PayPalApiTest.php index eb424ad..f6cfeed 100644 --- a/tests/phpunit/Adapter/PayPal/PayPalApiTest.php +++ b/tests/phpunit/Adapter/PayPal/PayPalApiTest.php @@ -27,6 +27,7 @@ } public function testGoodSubmit() { + TestingPaypalExpressAdapter::setDummyGatewayResponseCode( 'OK' ); $init = array( 'amount' => 1.55, 'currency' => 'USD', @@ -112,6 +113,7 @@ } public function testGoodRecurringSubmit() { + TestingPaypalExpressAdapter::setDummyGatewayResponseCode( 'OK' ); $init = array( 'amount' => 1.55, 'currency' => 'USD', diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php index 1a92a8f..d6b445a 100644 --- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php +++ b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php @@ -45,7 +45,7 @@ 'language' => 'fr', ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); + $gateway::setDummyGatewayResponseCode( 'OK' ); $result = $gateway->doPayment(); $gateway->logPending(); // GatewayPage or the API calls this for redirects $this->assertEquals( @@ -98,7 +98,7 @@ 'language' => 'fr', ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); + TestingPaypalExpressAdapter::setDummyGatewayResponseCode( 'OK' ); $result = $gateway->doPayment(); $gateway->logPending(); // GatewayPage or the API calls this for redirects $this->assertEquals( @@ -148,7 +148,7 @@ $this->setUpRequest( $init, array( 'Donor' => $init ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'OK' ); + TestingPaypalExpressAdapter::setDummyGatewayResponseCode( 'OK' ); $gateway->processDonorReturn( array( 'token' => 'EC%2d4V987654XA123456V', 'PayerID' => 'ASDASD', @@ -198,7 +198,7 @@ $init['recurring'] = '1'; $this->setUpRequest( $init, array( 'Donor' => $init ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( 'Recurring-OK' ); + $gateway::setDummyGatewayResponseCode( 'Recurring-OK' ); $gateway->processDonorReturn( array( 'token' => 'EC%2d4V987654XA123456V', 'PayerID' => 'ASDASD' @@ -217,7 +217,7 @@ $this->setUpRequest( $init, array( 'Donor' => $init ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '10486' ); + $gateway::setDummyGatewayResponseCode( '10486' ); $result = $gateway->processDonorReturn( array( 'token' => 'EC%2d2D123456D9876543U', 'PayerID' => 'ASDASD' @@ -239,7 +239,7 @@ $init['recurring'] = '1'; $this->setUpRequest( $init, array( 'Donor' => $init ) ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '10486' ); + $gateway::setDummyGatewayResponseCode( '10486' ); $result = $gateway->processDonorReturn( array( 'token' => 'EC%2d2D123456D9876543U', 'PayerID' => 'ASDASD' @@ -263,6 +263,7 @@ */ public function testResultSwitcher() { $init = $this->getDonorTestData( 'US' ); + TestingPaypalExpressAdapter::setDummyGatewayResponseCode( 'OK' ); $init['contribution_tracking_id'] = '45931210'; $init['gateway_session_id'] = mt_rand(); $init['language'] = 'pt'; diff --git a/tests/phpunit/DonationInterfaceApiTestCase.php b/tests/phpunit/DonationInterfaceApiTestCase.php index 0abf33f..a5509bf 100644 --- a/tests/phpunit/DonationInterfaceApiTestCase.php +++ b/tests/phpunit/DonationInterfaceApiTestCase.php @@ -17,10 +17,7 @@ } public function tearDown() { + DonationInterfaceTestCase::resetAllEnv(); parent::tearDown(); - Context::set( null ); - // Clear out our HashBagOStuff - wfGetMainCache()->clear(); - DonationLoggerFactory::$overrideLogger = null; } } diff --git a/tests/phpunit/DonationInterfaceTestCase.php b/tests/phpunit/DonationInterfaceTestCase.php index b8f7840..0873887 100644 --- a/tests/phpunit/DonationInterfaceTestCase.php +++ b/tests/phpunit/DonationInterfaceTestCase.php @@ -67,6 +67,22 @@ parent::__construct( $name, $data, $dataName ); } + public static function resetTestingAdapters() { + $testing_adapters = array( + 'TestingAdyenAdapter', + 'TestingAmazonAdapter', + 'TestingAstroPayAdapter', + 'TestingGenericAdapter', + 'TestingGlobalCollectAdapter', + 'TestingGlobalCollectOrphanAdapter', + 'TestingPaypalExpressAdapter', + 'TestingPaypalLegacyAdapter', + ); + foreach ( $testing_adapters as $testing_adapter ) { + $testing_adapter::setDummyGatewayResponseCode( null ); + } + } + protected function setUp() { // TODO: Use SmashPig dependency injection instead. Also override // SmashPig core logger. @@ -81,8 +97,7 @@ } protected function tearDown() { - $this->resetAllEnv(); - DonationLoggerFactory::$overrideLogger = null; + self::resetAllEnv(); parent::tearDown(); } @@ -485,8 +500,7 @@ return $gateway; } - function resetAllEnv() { - // TODO: reset PDO/sqlite queues + public static function resetAllEnv() { $_SESSION = array ( ); $_GET = array ( ); $_POST = array ( ); @@ -499,6 +513,7 @@ RequestContext::resetMain(); + self::resetTestingAdapters(); // Wipe out the $instance of these classes to make sure they're // re-created with fresh gateway instances for the next test $singleton_classes = array( @@ -519,6 +534,7 @@ Context::set( null ); // Clear out our HashBagOStuff, used for testing wfGetMainCache()->clear(); + DonationLoggerFactory::$overrideLogger = null; } /** diff --git a/tests/phpunit/LoggingTest.php b/tests/phpunit/LoggingTest.php index c452c85..df63491 100644 --- a/tests/phpunit/LoggingTest.php +++ b/tests/phpunit/LoggingTest.php @@ -77,7 +77,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '200' ); + $gateway::setDummyGatewayResponseCode( '200' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $preface_pattern = '/' . preg_quote( GatewayAdapter::COMPLETED_PREFACE ) . '/'; $matches = self::getLogMatches( LogLevel::INFO, $preface_pattern ); @@ -130,7 +130,7 @@ ); $gateway = $this->getFreshGatewayObject( $init ); - $gateway->setDummyGatewayResponseCode( '200' ); + $gateway::setDummyGatewayResponseCode( '200' ); $gateway->do_transaction( 'Confirm_CreditCard' ); $preface_pattern = '/' . preg_quote( GatewayAdapter::COMPLETED_PREFACE ) . '/'; $matches = self::getLogMatches( LogLevel::INFO, $preface_pattern ); diff --git a/tests/phpunit/MustacheFormTest.php b/tests/phpunit/MustacheFormTest.php index ecf84cd..10cf3a1 100644 --- a/tests/phpunit/MustacheFormTest.php +++ b/tests/phpunit/MustacheFormTest.php @@ -28,8 +28,6 @@ protected $gatewayPage; public function setUp() { - $this->resetAllEnv(); - $this->outputPage = $this->getMockBuilder( 'OutputPage' ) ->disableOriginalConstructor() ->setMethods( array( 'parse' ) ) diff --git a/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php b/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php index f7f780a..ce7c225 100644 --- a/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php +++ b/tests/phpunit/includes/test_gateway/TestingPaypalExpressAdapter.php @@ -5,8 +5,4 @@ */ class TestingPaypalExpressAdapter extends PaypalExpressAdapter { use TTestingAdapter; - public function __construct( array $options = array() ) { - $this->setDummyGatewayResponseCode( 'OK' ); - parent::__construct( $options ); - } } diff --git a/tests/phpunit/includes/test_gateway/test.adapter.php b/tests/phpunit/includes/test_gateway/test.adapter.php index 3f299bf..19769ac 100644 --- a/tests/phpunit/includes/test_gateway/test.adapter.php +++ b/tests/phpunit/includes/test_gateway/test.adapter.php @@ -21,6 +21,8 @@ public static $fakeIdentifier; + public static $dummyGatewayResponseCode = null; + public $curled = array(); public static function getIdentifier() { @@ -99,16 +101,10 @@ /** * Set the error code you want the dummy response to return + * @param $code */ - public function setDummyGatewayResponseCode( $code ) { - $this->dummyGatewayResponseCode = $code; - } - - /** - * Set the error code you want the dummy response to return - */ - public function setDummyCurlResponseCode( $code ) { - $this->dummyCurlResponseCode = $code; + public static function setDummyGatewayResponseCode( $code ) { + static::$dummyGatewayResponseCode = $code; } protected function curl_transaction( $data ) { @@ -121,13 +117,13 @@ */ protected function curl_exec( $ch ) { $code = ''; - if ( property_exists( $this, 'dummyGatewayResponseCode' ) ) { - if ( is_array( $this->dummyGatewayResponseCode ) ) { - $code = array_shift( $this->dummyGatewayResponseCode ); - } elseif ( is_callable( $this->dummyGatewayResponseCode ) ) { - $code = call_user_func( $this->dummyGatewayResponseCode, $this ); + if ( static::$dummyGatewayResponseCode !== null ) { + if ( is_array( static::$dummyGatewayResponseCode ) ) { + $code = array_shift( static::$dummyGatewayResponseCode ); + } elseif ( is_callable( static::$dummyGatewayResponseCode ) ) { + $code = call_user_func( static::$dummyGatewayResponseCode, $this ); } else { - $code = $this->dummyGatewayResponseCode; + $code = static::$dummyGatewayResponseCode; } } if ( $code ) { @@ -157,10 +153,7 @@ * Load in some dummy curl response info so we can test proper response processing */ protected function curl_getinfo( $ch, $opt = null ) { - $code = 200; //response OK - if ( property_exists( $this, 'dummyCurlResponseCode' ) ) { - $code = ( int ) $this->dummyCurlResponseCode; - } + $code = 200; //put more here if it ever turns out that we care about it. return array ( -- To view, visit https://gerrit.wikimedia.org/r/375086 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7d6321a3ef6767d50efe7173f1ad8c54efee2ab2 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/DonationInterface Gerrit-Branch: master Gerrit-Owner: Ejegg <ej...@ejegg.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits