jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/366161 )

Change subject: Make getLogMatches static
......................................................................


Make getLogMatches static

This will let us re-use it in API tests

Change-Id: Idfaff167388e9f338270d17307baf9d6a4643b69
---
M tests/phpunit/Adapter/AstroPay/AstroPayTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
M tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
M tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php
M tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
M tests/phpunit/DonationDataTest.php
M tests/phpunit/DonationInterfaceTestCase.php
M tests/phpunit/GatewayPageTest.php
M tests/phpunit/IntegrationTest.php
M tests/phpunit/LoggingTest.php
10 files changed, 25 insertions(+), 29 deletions(-)

Approvals:
  Mepps: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php 
b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
index 59e1185..24c5c54 100644
--- a/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
+++ b/tests/phpunit/Adapter/AstroPay/AstroPayTest.php
@@ -158,7 +158,7 @@
                        $errors[0]->getErrorCode(),
                        'Wrong error for code "1"'
                );
-               $logged = $this->getLogMatches( LogLevel::WARNING, '/This error 
message should appear in the log./' );
+               $logged = self::getLogMatches( LogLevel::WARNING, '/This error 
message should appear in the log./' );
                $this->assertNotEmpty( $logged );
        }
 
@@ -212,7 +212,7 @@
                        'Should be an error in PaymentResult'
                );
 
-               $logged = $this->getLogMatches( LogLevel::WARNING, '/This error 
message should appear in the log./' );
+               $logged = self::getLogMatches( LogLevel::WARNING, '/This error 
message should appear in the log./' );
                $this->assertNotEmpty( $logged );
                // TODO: Should this really be a refresh, or should we finalize 
to failed here?
                $this->assertTrue( $result->getRefresh(), 'PaymentResult should 
be a refresh' );
diff --git 
a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
index 8053400..86d457b 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectOrphanAdapterTest.php
@@ -151,7 +151,7 @@
                        return $error->getErrorCode() == '1000001';
                };
                $this->assertNotEmpty( array_filter( $errors, $finder ), 
'Orphan adapter needs error 1000001 to consider it rectified' );
-               $loglines = $this->getLogMatches( LogLevel::INFO, "/Got error 
code $code, not retrying to avoid MasterCard fines./" );
+               $loglines = self::getLogMatches( LogLevel::INFO, "/Got error 
code $code, not retrying to avoid MasterCard fines./" );
                $this->assertNotEmpty( $loglines, "GC Error $code is not 
generating the expected payments log error" );
        }
 
diff --git a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php 
b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
index 972d8b0..ee8e3d3 100644
--- a/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/GlobalCollectTest.php
@@ -423,18 +423,18 @@
                $gateway = $this->getFreshGatewayObject( $init );
                $gateway->setDummyGatewayResponseCode( '21000050' );
                $gateway->do_transaction( 'GET_ORDERSTATUS' );
-               $loglines = $this->getLogMatches( LogLevel::ERROR, 
'/Investigation required!/' );
+               $loglines = self::getLogMatches( LogLevel::ERROR, 
'/Investigation required!/' );
                $this->assertNotEmpty( $loglines, 'GC Error 21000050 is not 
generating the expected payments log error' );
 
                //Reset logs
-               $this->testLogger->messages = array();
+               DonationLoggerFactory::$overrideLogger->messages = array();
 
                //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->do_transaction( 'GET_ORDERSTATUS' );
                $this->verifyNoLogErrors();
-               $loglines = $this->getLogMatches( LogLevel::INFO, 
'/processResponse:.*EXPIRYDATE/' );
+               $loglines = self::getLogMatches( LogLevel::INFO, 
'/processResponse:.*EXPIRYDATE/' );
                $this->assertNotEmpty( $loglines, 'GC Error 20001000-expiry is 
not generating the expected payments log line' );
        }
 
@@ -530,7 +530,7 @@
                $start_id = $exposed->getData_Staged( 'order_id' );
                $gateway->do_transaction( 'Confirm_CreditCard' );
                $finish_id = $exposed->getData_Staged( 'order_id' );
-               $loglines = $this->getLogMatches( LogLevel::INFO, '/Repeating 
transaction on request for vars:/' );
+               $loglines = self::getLogMatches( LogLevel::INFO, '/Repeating 
transaction on request for vars:/' );
                $this->assertEmpty( $loglines, "Log says we are going to repeat 
the transaction for code $code, but that is not true" );
                $this->assertEquals( $start_id, $finish_id, "Needlessly 
regenerated order id for code $code ");
        }
@@ -595,7 +595,7 @@
                $gateway = $this->getFreshGatewayObject( $init );
                $gateway->setDummyGatewayResponseCode( '11000400' );
                $gateway->do_transaction( 'SET_PAYMENT' );
-               $loglines = $this->getLogMatches( LogLevel::INFO, '/Repeating 
transaction for timeout/' );
+               $loglines = self::getLogMatches( LogLevel::INFO, '/Repeating 
transaction for timeout/' );
                $this->assertNotEmpty( $loglines, "Log does not say we retried 
for timeout." );
        }
 
diff --git a/tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php 
b/tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php
index f56357f..9e124d8 100644
--- a/tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php
+++ b/tests/phpunit/Adapter/GlobalCollect/ResultSwitcherTest.php
@@ -48,9 +48,9 @@
 
                $this->verifyFormOutput( 'GlobalCollectGatewayResult', 
$request, $assertNodes, false, $session );
                // Make sure we logged the expected cURL attempts
-               $messages = $this->getLogMatches( 'info', '/Preparing to send 
GET_ORDERSTATUS transaction to Global Collect/' );
+               $messages = self::getLogMatches( 'info', '/Preparing to send 
GET_ORDERSTATUS transaction to Global Collect/' );
                $this->assertNotEmpty( $messages );
-               $messages = $this->getLogMatches( 'info', '/Preparing to send 
SET_PAYMENT transaction to Global Collect/' );
+               $messages = self::getLogMatches( 'info', '/Preparing to send 
SET_PAYMENT transaction to Global Collect/' );
                $this->assertNotEmpty( $messages );
     }
 }
diff --git a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php 
b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
index 7ea9f12..b85a39c 100644
--- a/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
+++ b/tests/phpunit/Adapter/PayPal/PayPalExpressTest.php
@@ -268,9 +268,9 @@
                $this->assertArrayHasKey( $request['token'], $processed );
 
                // Make sure we logged the expected cURL attempts
-               $messages = $this->getLogMatches( 'info', '/Preparing to send 
GetExpressCheckoutDetails transaction to Paypal Express Checkout/' );
+               $messages = self::getLogMatches( 'info', '/Preparing to send 
GetExpressCheckoutDetails transaction to Paypal Express Checkout/' );
                $this->assertNotEmpty( $messages );
-               $messages = $this->getLogMatches( 'info', '/Preparing to send 
DoExpressCheckoutPayment transaction to Paypal Express Checkout/' );
+               $messages = self::getLogMatches( 'info', '/Preparing to send 
DoExpressCheckoutPayment transaction to Paypal Express Checkout/' );
                $this->assertNotEmpty( $messages );
        }
 
@@ -309,7 +309,7 @@
                $this->verifyFormOutput( 'PaypalExpressGatewayResult', 
$request, $assertNodes, false, $session );
 
                // We should not have logged any cURL attempts
-               $messages = $this->getLogMatches( 'info', '/Preparing to send 
.*/' );
+               $messages = self::getLogMatches( 'info', '/Preparing to send 
.*/' );
                $this->assertEmpty( $messages );
        }
 }
diff --git a/tests/phpunit/DonationDataTest.php 
b/tests/phpunit/DonationDataTest.php
index 66e7564..d11a0bd 100644
--- a/tests/phpunit/DonationDataTest.php
+++ b/tests/phpunit/DonationDataTest.php
@@ -221,9 +221,9 @@
                $this->setUpRequest( $expected );
 
                $ddObj = new DonationData( $this->getFreshGatewayObject( ) );
-               $matches = $this->getLogMatches( LogLevel::DEBUG, 
'/setUtmSource: Payment method is cc, recurring = NULL, utm_source = cc$/' );
+               $matches = self::getLogMatches( LogLevel::DEBUG, 
'/setUtmSource: Payment method is cc, recurring = NULL, utm_source = cc$/' );
                $this->assertNotEmpty( $matches );
-               $matches = $this->getLogMatches( LogLevel::DEBUG, "/Got 
currency from 'currency', now: USD$/" );
+               $matches = self::getLogMatches( LogLevel::DEBUG, "/Got currency 
from 'currency', now: USD$/" );
                $this->assertNotEmpty( $matches );
        }
 
diff --git a/tests/phpunit/DonationInterfaceTestCase.php 
b/tests/phpunit/DonationInterfaceTestCase.php
index a418960..7199e72 100644
--- a/tests/phpunit/DonationInterfaceTestCase.php
+++ b/tests/phpunit/DonationInterfaceTestCase.php
@@ -49,10 +49,6 @@
         */
        protected $gatewayAdapter;
 
-       /**
-        * @var TestingDonationLogger
-        */
-       protected $testLogger;
        protected $testAdapterClass = TESTS_ADAPTER_DEFAULT;
        protected $smashPigGlobalConfig;
 
@@ -73,8 +69,7 @@
        protected function setUp() {
                // TODO: Use SmashPig dependency injection instead.  Also 
override
                // SmashPig core logger.
-               $this->testLogger = new TestingDonationLogger();
-               DonationLoggerFactory::$overrideLogger = $this->testLogger;
+               DonationLoggerFactory::$overrideLogger = new 
TestingDonationLogger();
                $this->setMwGlobals( array(
                        'wgDonationInterfaceEnableQueue' => true,
                        'wgDonationInterfaceDefaultQueueServer' => array(
@@ -658,7 +653,7 @@
         * Asserts that there are no log entries of LOG_ERR or worse.
         */
        function verifyNoLogErrors( ) {
-               $log = $this->testLogger->messages;
+               $log = DonationLoggerFactory::$overrideLogger->messages;
 
                $this->assertTrue( is_array( $log ), "Missing the test log" );
 
@@ -687,8 +682,8 @@
         * @return array All log lines that match $match.
         *     FIXME: Or false.  Return an empty array or throw an exception 
instead.
         */
-       public function getLogMatches( $log_level, $match ) {
-               $log = $this->testLogger->messages;
+       public static function getLogMatches( $log_level, $match ) {
+               $log = DonationLoggerFactory::$overrideLogger->messages;
                if ( !array_key_exists( $log_level, $log ) ) {
                        return false;
                }
diff --git a/tests/phpunit/GatewayPageTest.php 
b/tests/phpunit/GatewayPageTest.php
index 74b651d..225c7f0 100644
--- a/tests/phpunit/GatewayPageTest.php
+++ b/tests/phpunit/GatewayPageTest.php
@@ -166,7 +166,7 @@
 
                $this->verifyFormOutput( 'PaypalLegacyGateway', $init, array(), 
false, $session );
 
-               $logged = $this->getLogMatches( LogLevel::INFO, '/^Redirecting 
for transaction: /' );
+               $logged = self::getLogMatches( LogLevel::INFO, '/^Redirecting 
for transaction: /' );
                $this->assertEquals( 1, count( $logged ), 'Should have logged 
details once' );
                preg_match( '/Redirecting for transaction: (.*)$/', $logged[0], 
$matches );
                $detailString = $matches[1];
diff --git a/tests/phpunit/IntegrationTest.php 
b/tests/phpunit/IntegrationTest.php
index 26f7d52..d78d3d9 100644
--- a/tests/phpunit/IntegrationTest.php
+++ b/tests/phpunit/IntegrationTest.php
@@ -82,8 +82,9 @@
                $this->assertEmpty( $response->getErrors() );
 
                $errors = '';
-               if ( array_key_exists( LogLevel::ERROR, 
$this->testLogger->messages ) ) {
-                       foreach ( $this->testLogger->messages[LogLevel::ERROR] 
as $msg ) {
+               $messages = DonationLoggerFactory::$overrideLogger->messages;
+               if ( array_key_exists( LogLevel::ERROR, $messages ) ) {
+                       foreach ( $messages[LogLevel::ERROR] as $msg ) {
                                $errors .= "$msg\n";
                        }
                }
diff --git a/tests/phpunit/LoggingTest.php b/tests/phpunit/LoggingTest.php
index 87f0bba..c452c85 100644
--- a/tests/phpunit/LoggingTest.php
+++ b/tests/phpunit/LoggingTest.php
@@ -80,7 +80,7 @@
                $gateway->setDummyGatewayResponseCode( '200' );
                $gateway->do_transaction( 'Confirm_CreditCard' );
                $preface_pattern = '/' . preg_quote( 
GatewayAdapter::COMPLETED_PREFACE ) . '/';
-               $matches = $this->getLogMatches( LogLevel::INFO, 
$preface_pattern );
+               $matches = self::getLogMatches( LogLevel::INFO, 
$preface_pattern );
                $this->assertTrue( $matches !== false,
                        'Should log a completion message' );
 
@@ -133,7 +133,7 @@
                $gateway->setDummyGatewayResponseCode( '200' );
                $gateway->do_transaction( 'Confirm_CreditCard' );
                $preface_pattern = '/' . preg_quote( 
GatewayAdapter::COMPLETED_PREFACE ) . '/';
-               $matches = $this->getLogMatches( LogLevel::INFO, 
$preface_pattern );
+               $matches = self::getLogMatches( LogLevel::INFO, 
$preface_pattern );
                $this->assertTrue( $matches !== false,
                        'Should log a completion message' );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/366161
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Idfaff167388e9f338270d17307baf9d6a4643b69
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DonationInterface
Gerrit-Branch: master
Gerrit-Owner: Ejegg <ej...@ejegg.com>
Gerrit-Reviewer: AndyRussG <andrew.green...@gmail.com>
Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org>
Gerrit-Reviewer: Mepps <me...@wikimedia.org>
Gerrit-Reviewer: XenoRyet <dkozlow...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to