jenkins-bot has submitted this change and it was merged. Change subject: Merge branch 'master' into deployment ......................................................................
Merge branch 'master' into deployment af62f8d Revert "Put an ampersand on it, maybe it'll work" 83c139b Revert "Get all queues with QueueFactory::getQueue" Change-Id: Ie3313b6486dc082b854a957fd2fea0b0de7ac118 --- D PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php D PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php D PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php D Tests/QueueConsumerTest.php 4 files changed, 0 insertions(+), 656 deletions(-) Approvals: Ejegg: Looks good to me, approved jenkins-bot: Verified diff --git a/PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php b/PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php deleted file mode 100644 index e297329..0000000 --- a/PaymentProviders/Adyen/Tests/phpunit/CaptureJobTest.php +++ /dev/null @@ -1,238 +0,0 @@ -<<<<<<< HEAD (40c4a7 Merge branch 'master' into 'deployment') -======= -<?php namespace SmashPig\PaymentProviders\Adyen\Test; - -use PHPQueue\Backend\PDO; -use SmashPig\Core\Configuration; -use SmashPig\Core\Context; -use SmashPig\Core\DataStores\KeyedOpaqueStorableObject; -use SmashPig\Core\DataStores\PendingDatabase; -use SmashPig\Core\QueueConsumers\BaseQueueConsumer; -use SmashPig\PaymentProviders\Adyen\Jobs\ProcessCaptureRequestJob; -use SmashPig\PaymentProviders\Adyen\Tests\AdyenTestConfiguration; -use SmashPig\Tests\BaseSmashPigUnitTestCase; - -/** - * Verify Adyen Capture job functions - */ -class CaptureJobTest extends BaseSmashPigUnitTestCase { - - /** - * @var Configuration - */ - public $config; - /** - * @var PendingDatabase - */ - protected $pendingDatabase; - protected $pendingMessage; - /** - * @var PDO - */ - protected $antifraudQueue; - - public function setUp() { - parent::setUp(); - $this->config = AdyenTestConfiguration::createWithSuccessfulApi(); - Context::initWithLogger( $this->config ); - $this->pendingDatabase = PendingDatabase::get(); - $this->pendingMessage = json_decode( - file_get_contents( __DIR__ . '/../Data/pending.json' ) , true - ); - $this->pendingDatabase->storeMessage( $this->pendingMessage ); - $this->antifraudQueue = BaseQueueConsumer::getQueue( 'payments-antifraud' ); - } - - public function tearDown() { - $this->pendingDatabase->deleteMessage( $this->pendingMessage ); - parent::tearDown(); - } - - /** - * For a legit donation, ProcessCaptureJob should leave donor data - * in the pending database, add an antifraud message, and return true. - */ - public function testSuccessfulCapture() { - $api = $this->config->object( 'payment-provider/adyen/api', true ); - - $auth = KeyedOpaqueStorableObject::fromJsonProxy( - 'SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Authorisation', - file_get_contents( __DIR__ . '/../Data/auth.json' ) - ); - - $job = ProcessCaptureRequestJob::factory( $auth ); - $this->assertTrue( $job->execute() ); - - $donorData = $this->pendingDatabase->fetchMessageByGatewayOrderId( - 'adyen', $auth->merchantReference - ); - - $this->assertNotNull( - $donorData, - 'RequestCaptureJob did not leave donor data on pending queue' - ); - $this->assertTrue( - $donorData['captured'], - 'RequestCaptureJob did not mark donor data as captured' - ); - - $this->assertEquals( - array( - 'currency' => 'USD', - 'amount' => 10, - 'pspReference' => '762895314225', - ), - $api->captured[0], - 'RequestCaptureJob did not make the right capture call' - ); - - $antifraudMessage = $this->antifraudQueue->pop(); - $this->assertNotNull( - $antifraudMessage, - 'RequestCaptureJob did not send antifraud message' - ); - $this->assertEquals( - 'process', - $antifraudMessage['validation_action'], - 'Successful capture should get "process" validation action' - ); - } - - /** - * When AVS and CVV scores push the donation over the review threshold, - * we should not capture the payment, but leave the donor details. - */ - public function testReviewThreshold() { - $api = $this->config->object( 'payment-provider/adyen/api', true ); - - $auth = KeyedOpaqueStorableObject::fromJsonProxy( - 'SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Authorisation', - file_get_contents( __DIR__ . '/../Data/auth.json' ) - ); - - $auth->avsResult = '1'; // Bad zip code pushes us over review - - $job = ProcessCaptureRequestJob::factory( $auth ); - $this->assertTrue( $job->execute() ); - - $donorData = $this->pendingDatabase->fetchMessageByGatewayOrderId( - 'adyen', $auth->merchantReference - ); - $this->assertNotNull( - $donorData, - 'RequestCaptureJob did not leave donor data for review' - ); - $this->assertTrue( - empty( $donorData['captured'] ), - 'RequestCaptureJob marked donor data above review threshold as captured' - ); - - $this->assertEmpty( - $api->captured, - 'RequestCaptureJob tried to capture above review threshold' - ); - - $antifraudMessage = $this->antifraudQueue->pop(); - $this->assertNotNull( - $antifraudMessage, - 'RequestCaptureJob did not send antifraud message' - ); - $this->assertEquals( - 'review', - $antifraudMessage['validation_action'], - 'Suspicious auth should get "review" validation action' - ); - } - - /** - * When AVS and CVV scores push the donation over the reject threshold, - * we should cancel the authorization and delete the donor details. - */ - public function testRejectThreshold() { - $api = $this->config->object( 'payment-provider/adyen/api', true ); - - $auth = KeyedOpaqueStorableObject::fromJsonProxy( - 'SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Authorisation', - file_get_contents( __DIR__ . '/../Data/auth.json' ) - ); - - $auth->avsResult = '2'; // No match at all - $auth->cvvResult = '2'; // CVV is also wrong - - $job = ProcessCaptureRequestJob::factory( $auth ); - $this->assertTrue( $job->execute() ); - - $donorData = $this->pendingDatabase->fetchMessageByGatewayOrderId( - 'adyen', $auth->merchantReference - ); - $this->assertNull( - $donorData, - 'RequestCaptureJob should delete fraudy donor data' - ); - - $this->assertEmpty( - $api->captured, - 'RequestCaptureJob tried to capture above reject threshold' - ); - $this->assertEquals( - $auth->pspReference, - $api->cancelled[0], - 'Did not cancel the fraudulent authorization' - ); - - $antifraudMessage = $this->antifraudQueue->pop(); - $this->assertNotNull( - $antifraudMessage, - 'RequestCaptureJob did not send antifraud message' - ); - $this->assertEquals( - 'reject', - $antifraudMessage['validation_action'], - 'Obvious fraud should get "reject" validation action' - ); - } - - /** - * When two authorizations come in with the same merchant reference, we - * should cancel the second one and leave the donor details in pending. - */ - public function testDuplicateAuthorisation() { - $api = $this->config->object( 'payment-provider/adyen/api', true ); - - $auth1 = KeyedOpaqueStorableObject::fromJsonProxy( - 'SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Authorisation', - file_get_contents( __DIR__ . '/../Data/auth.json' ) - ); - $job1 = ProcessCaptureRequestJob::factory( $auth1 ); - $job1->execute(); - - $this->assertEquals( 1, count( $api->captured ), 'Set up failed' ); - - $auth2 = KeyedOpaqueStorableObject::fromJsonProxy( - 'SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Authorisation', - file_get_contents( __DIR__ . '/../Data/auth.json' ) - ); - $auth2->pspReference = mt_rand( 1000000000, 10000000000 ); - $job2 = ProcessCaptureRequestJob::factory( $auth2 ); - $this->assertTrue( - $job2->execute(), - 'Duplicate auths should not clutter damage queue' - ); - - $this->assertEquals( 1, count( $api->captured ), 'Captured a duplicate!' ); - $this->assertEquals( - $auth2->pspReference, - $api->cancelled[0], - 'Did not cancel the right authorization' - ); - - $this->assertNotNull( - $this->pendingDatabase->fetchMessageByGatewayOrderId( - 'adyen', $auth1->merchantReference - ), - 'Capture job should leave donor details in database' - ); - } - -} ->>>>>>> BRANCH (83c139 Revert "Get all queues with QueueFactory::getQueue") diff --git a/PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php b/PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php deleted file mode 100644 index ad41145..0000000 --- a/PaymentProviders/Adyen/Tests/phpunit/RecordCaptureJobTest.php +++ /dev/null @@ -1,93 +0,0 @@ -<<<<<<< HEAD (40c4a7 Merge branch 'master' into 'deployment') -======= -<?php namespace SmashPig\PaymentProviders\Adyen\Test; - -use SmashPig\Core\Configuration; -use SmashPig\Core\Context; -use SmashPig\Core\DataStores\KeyedOpaqueStorableObject; -use SmashPig\Core\DataStores\PendingDatabase; -use SmashPig\Core\QueueConsumers\BaseQueueConsumer; -use SmashPig\PaymentProviders\Adyen\Jobs\RecordCaptureJob; -use SmashPig\PaymentProviders\Adyen\Tests\AdyenTestConfiguration; -use SmashPig\Tests\BaseSmashPigUnitTestCase; - -/** - * Verify Adyen RecordCapture job functions - */ -class RecordCaptureJobTest extends BaseSmashPigUnitTestCase { - - /** - * @var Configuration - */ - public $config; - /** - * @var PendingDatabase - */ - protected $pendingDatabase; - protected $pendingMessage; - - public function setUp() { - parent::setUp(); - $this->config = AdyenTestConfiguration::createWithSuccessfulApi(); - Context::initWithLogger( $this->config ); - $this->pendingDatabase = PendingDatabase::get(); - $this->pendingMessage = json_decode( - file_get_contents( __DIR__ . '/../Data/pending.json' ) , true - ); - $this->pendingMessage['captured'] = true; - $this->pendingDatabase->storeMessage( $this->pendingMessage ); - } - - public function tearDown() { - $this->pendingDatabase->deleteMessage( $this->pendingMessage ); - parent::tearDown(); - } - - public function testRecordCapture() { - $verifiedQueue = BaseQueueConsumer::getQueue( 'verified' ); - $verifiedQueue->createTable( 'verified' ); - - $capture = KeyedOpaqueStorableObject::fromJsonProxy( - 'SmashPig\PaymentProviders\Adyen\ExpatriatedMessages\Capture', - file_get_contents( __DIR__ . '/../Data/capture.json' ) - ); - - $job = RecordCaptureJob::factory( $capture ); - $this->assertTrue( $job->execute() ); - - $donorData = $this->pendingDatabase->fetchMessageByGatewayOrderId( - 'adyen', $capture->merchantReference - ); - - $this->assertNull( - $donorData, - 'RecordCaptureJob left donor data on pending queue' - ); - - $verifiedMessage = $verifiedQueue->pop(); - $this->assertNotNull( - $verifiedMessage, - 'RecordCaptureJob did not send verified message' - ); - // can we use arraySubset yet? - $sameKeys = array_intersect( - array_keys( $verifiedMessage ), - array_keys( $this->pendingMessage ) - ); - foreach ( $sameKeys as $key ) { - if ( $key === 'gateway_txn_id' ) { - $this->assertEquals( - $capture->originalReference, $verifiedMessage[$key], - 'RecordCaptureJob should have set gateway_txn_id' - ); - } else { - $this->assertEquals( - $this->pendingMessage[$key], - $verifiedMessage[$key], - "Value of key $key mutated" - ); - } - } - } -} ->>>>>>> BRANCH (83c139 Revert "Get all queues with QueueFactory::getQueue") diff --git a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php b/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php deleted file mode 100644 index a525eb4..0000000 --- a/PaymentProviders/PayPal/Tests/phpunit/CaptureIncomingMessageTest.php +++ /dev/null @@ -1,128 +0,0 @@ -<<<<<<< HEAD (40c4a7 Merge branch 'master' into 'deployment') -======= -<?php -namespace SmashPig\PaymentProviders\PayPal\Tests; - -use SmashPig\Core\Configuration; -use SmashPig\Core\Context; -use SmashPig\Core\QueueConsumers\BaseQueueConsumer; -use SmashPig\PaymentProviders\PayPal\Listener; -use SmashPig\PaymentProviders\PayPal\Job; -use SmashPig\PaymentProviders\PayPal\Tests\PayPalTestConfiguration; -use SmashPig\Tests\BaseSmashPigUnitTestCase; -use SmashPig\Core\Http\Response; -use SmashPig\Core\Http\Request; -use SmashPig\Core\DataStores\KeyedOpaqueStorableObject; - -/** - * Test the IPN listener which receives messages, stores and processes them. - */ -class CaptureIncomingMessageTest extends BaseSmashPigUnitTestCase { - - /** - * @var Configuration - */ - public $config; - - static $fail_verification = false; - - static $message_locations = array( - 'verified' => 'web_accept.json', - 'recurring' => 'subscr_signup.json', - 'recurring' => 'subscr_payment.json' - ); - - static $messages = array(); - - public function setUp() { - parent::setUp(); - $this->config = PayPalTestConfiguration::get(); - - // php-queue\PDO complains about pop() from non-existent table - $this->config->object( 'data-store/jobs-paypal' ) - ->createTable( 'jobs-paypal' ); - - Context::initWithLogger( $this->config ); - foreach ( self::$message_locations as $type => $file ) { - self::$messages[$type] = json_decode( - file_get_contents( __DIR__ . '/../Data/' . $file ), - true - ); - } - } - - private function capture( $msg ) { - $request = new Request( $msg ); - $response = new Response; - $listener = new Listener; - $listener->execute( $request, $response ); - } - - public function testCapture() { - foreach ( self::$messages as $type => $msg ) { - - $this->capture( $msg ); - - $jobQueue = $this->config->object( 'data-store/jobs-paypal' ); - $jobMessage = $jobQueue->pop(); - - $this->assertEquals( $jobMessage['php-message-class'], - 'SmashPig\PaymentProviders\PayPal\Job' ); - - $this->assertEquals( $jobMessage['payload'], $msg ); - - } - } - - public function testBlankMessage() { - $this->capture( array() ); - $jobQueue = $this->config->object( 'data-store/jobs-paypal' ); - $this->assertNull( $jobQueue->pop() ); - } - - public function testConsume() { - foreach ( self::$messages as $type => $msg ) { - $this->capture( $msg ); - - $jobQueue = $this->config->object( 'data-store/jobs-paypal' ); - $jobMessage = $jobQueue->pop(); - - $job = KeyedOpaqueStorableObject::fromJsonProxy( - $jobMessage['php-message-class'], - json_encode( $jobMessage ) - ); - - $job->execute(); - - $queue = $this->config->object( 'data-store/' . $type ); - $queue->createTable( $type ); - $message = $queue->pop(); - - $this->assertNotEmpty( $message ); - - } - } - - public function testFailedConsume() { - self::$fail_verification = true; - $jobMessage = array( 'txn_type' => 'fail' ); - $jobClass = 'SmashPig\PaymentProviders\PayPal\Job'; - $job = KeyedOpaqueStorableObject::fromJsonProxy( - $jobClass, - json_encode( $jobMessage ) - ); - - try { - $job->execute(); - } catch ( \Exception $e ) { - // TODO I think this can throw a special exception to move to - // damaged queue or some other stuff - $this->assertEquals( - \SmashPig\PaymentProviders\PayPal\Job::$verifyFailedMsg, - $e->getMessage() - ); - } - - } -} ->>>>>>> BRANCH (83c139 Revert "Get all queues with QueueFactory::getQueue") diff --git a/Tests/QueueConsumerTest.php b/Tests/QueueConsumerTest.php deleted file mode 100644 index 624da2e..0000000 --- a/Tests/QueueConsumerTest.php +++ /dev/null @@ -1,197 +0,0 @@ -<<<<<<< HEAD (40c4a7 Merge branch 'master' into 'deployment') -======= -<?php - -namespace SmashPig\Tests; - -use Exception; -use PDO; -use PHPQueue\Interfaces\FifoQueueStore; -use SmashPig\Core\Context; -use SmashPig\Core\DataStores\DamagedDatabase; -use SmashPig\Core\QueueConsumers\BaseQueueConsumer; - -class QueueConsumerTest extends BaseSmashPigUnitTestCase { - - /** - * @var FifoQueueStore - */ - protected $queue; - /** - * @var PDO - */ - protected $damaged; - - public function setUp() { - parent::setUp(); - Context::initWithLogger( QueueTestConfiguration::instance() ); - $this->queue = BaseQueueConsumer::getQueue( 'test' ); - $this->queue->createTable( 'test' ); - $damagedDb = DamagedDatabase::get(); - $damagedDb->createTable(); - $this->damaged = $damagedDb->getDatabase(); - } - - public function testEmptyQueue() { - $consumer = new TestingQueueConsumer( 'test' ); - $count = $consumer->dequeueMessages(); - $this->assertEquals( 0, $count, 'Should report 0 messages processed' ); - } - - public function testOneMessage() { - $consumer = new TestingQueueConsumer( 'test' ); - $payload = array( - 'wednesday' => 'addams', - 'spookiness' => mt_rand(), - ); - $this->queue->push( $payload ); - $count = $consumer->dequeueMessages(); - $this->assertEquals( 1, $count, 'Should report 1 message processed' ); - $this->assertEquals( array( $payload ), $consumer->processed, 'Bad message' ); - $this->assertNull( $this->queue->pop(), - 'Should delete message when processing is successful' - ); - } - - public function testDamagedQueue() { - $payload = array( - 'gateway' => 'test', - 'date' => time(), - 'order_id' => mt_rand(), - 'cousin' => 'itt', - 'kookiness' => mt_rand(), - ); - - $consumer = new TestingQueueConsumer( 'test' ); - $consumer->exception = new Exception( 'kaboom!' ); - - $this->queue->push( $payload ); - try { - $consumer->dequeueMessages(); - } catch ( Exception $ex ) { - $this->fail( - 'Exception should not have bubbled up: ' . $ex->getMessage() - ); - } - $this->assertEquals( - array( $payload ), - $consumer->processed, - 'Processing snafu' - ); - - $damaged = $this->getDamagedQueueMessage( $payload ); - $this->assertEquals( - $payload, - $damaged, - 'Should move message to damaged queue when exception is thrown' - ); - $this->assertNull( - $this->queue->pop(), - 'Should delete message on exception when damaged queue exists' - ); - } - - public function testMessageLimit() { - $messages = array(); - for ( $i = 0; $i < 5; $i++ ) { - $message = array( - 'gateway' => 'test', - 'date' => time(), - 'order_id' => mt_rand(), - 'box' => 'thing' . $i, - 'creepiness' => mt_rand(), - ); - $messages[] = $message; - $this->queue->push( $message ); - } - // Should work when you pass in the limits as strings. - $consumer = new TestingQueueConsumer( 'test', 0, '3' ); - $count = $consumer->dequeueMessages(); - $this->assertEquals( - 3, $count, 'dequeueMessages returned wrong count' - ); - $this->assertEquals( - 3, - count( $consumer->processed ), - 'Called callback wrong number of times' - ); - - for ( $i = 0; $i < 3; $i++ ) { - $this->assertEquals( - $messages[$i], - $consumer->processed[$i], - 'Message mutated' - ); - } - $this->assertEquals( - $messages[3], - $this->queue->pop(), - 'Dequeued too many messages' - ); - } - - public function testKeepRunningOnDamage() { - $messages = array(); - for ( $i = 0; $i < 5; $i++ ) { - $message = array( - 'gateway' => 'test', - 'date' => time(), - 'order_id' => mt_rand(), - 'box' => 'thing' . $i, - 'creepiness' => mt_rand(), - ); - $messages[] = $message; - $this->queue->push( $message ); - } - - $consumer = new TestingQueueConsumer( 'test', 0, 3 ); - $consumer->exception = new Exception( 'Kaboom!' ); - $count = 0; - try { - $count = $consumer->dequeueMessages(); - } catch ( Exception $ex ) { - $this->fail( - 'Exception should not have bubbled up: ' . $ex->getMessage() - ); - } - $this->assertEquals( - 3, $count, 'dequeueMessages returned wrong count' - ); - $this->assertEquals( - 3, - count( $consumer->processed ), - 'Called callback wrong number of times' - ); - - for ( $i = 0; $i < 3; $i++ ) { - $this->assertEquals( - $messages[$i], $consumer->processed[$i], 'Message mutated' - ); - $damaged = $this->getDamagedQueueMessage( $messages[$i] ); - $this->assertEquals( - $messages[$i], - $damaged, - 'Should move message to damaged queue when exception is thrown' - ); - } - $this->assertEquals( - $messages[3], - $this->queue->pop(), - 'message 4 should be at the head of the queue' - ); - } - - protected function getDamagedQueueMessage( $message ) { - $select = $this->damaged->query( " - SELECT * FROM damaged - WHERE gateway='{$message['gateway']}' - AND order_id = '{$message['order_id']}'" ); - $msg = $select->fetch( PDO::FETCH_ASSOC ); - if ( $msg ) { - return json_decode( $msg['message'], true ); - } - return null; - } - -} ->>>>>>> BRANCH (83c139 Revert "Get all queues with QueueFactory::getQueue") -- To view, visit https://gerrit.wikimedia.org/r/313431 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ie3313b6486dc082b854a957fd2fea0b0de7ac118 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/SmashPig Gerrit-Branch: deployment Gerrit-Owner: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits