r100942 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r100941‎ | r100942 | r100943 >
Date:03:47, 27 October 2011
Author:jpostlethwaite
Status:deferred (Comments)
Tags:fundraising 
Comment:
Added GlobalCollectTestAdapter for testing the GlobalCollect adapter.
Modified paths:
  • /trunk/extensions/DonationInterface/tests/Adapter/GlobalCollect/GlobalCollectTestAdapter.php (added) (history)

Diff [purge]

Index: trunk/extensions/DonationInterface/tests/Adapter/GlobalCollect/GlobalCollectTestAdapter.php
@@ -0,0 +1,37 @@
 2+<?php
 3+/**
 4+ * Wikimedia Foundation
 5+ *
 6+ * LICENSE
 7+ *
 8+ * This program is free software; you can redistribute it and/or modify
 9+ * it under the terms of the GNU General Public License as published by
 10+ * the Free Software Foundation; either version 2 of the License, or
 11+ * (at your option) any later version.
 12+ *
 13+ * This program is distributed in the hope that it will be useful,
 14+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 16+ * GNU General Public License for more details.
 17+ *
 18+ *
 19+ * @since r100942
 20+ * @author Jeremy Postlethwaite <jpostlethwaite@wikimedia.org>
 21+ */
 22+
 23+/**
 24+ * GlobalCollectTestAdapter
 25+ */
 26+class GlobalCollectTestAdapter extends GlobalCollectAdapter {
 27+
 28+ /**
 29+ * This allows buildRequestXML() to be called for unit testing.
 30+ *
 31+ * @see GatewayAdapter::buildRequestXML()
 32+ */
 33+ public function executeBuildRequestXML() {
 34+
 35+ return $this->buildRequestXML();
 36+ }
 37+}
 38+
Property changes on: trunk/extensions/DonationInterface/tests/Adapter/GlobalCollect/GlobalCollectTestAdapter.php
___________________________________________________________________
Added: svn:eol-style
139 + native
Added: svn:mime-type
240 + text/plain
Added: svn:keywords
341 + Author Date HeadURL Header Id Revision

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r100622Made currentTransaction() public for unit testing. Added getDonationData() fo...jpostlethwaite17:25, 24 October 2011

Comments

#Comment by Khorn (WMF) (talk | contribs)   16:58, 27 October 2011

Awesome. You may want to consider adding back in some of the functionality you killed off in r100625. Particularly, the part where the curl function was being overridden to ensure that tests you do using this object remain local, but that it returns _something_ (under your control, of course) that the rest of the object can handle normally. In my experience, it is a _very_ good idea to strongly segregate all your local testing, from everything that might have the slightest, remotest possibility of actually contacting a server, particularly if it has the slightest possibility of triggering real money changing hands in a rapid-fire, automated kind of way. The best way to do this is to always ONLY run automated tests on a special object, on which you have specially damaged the outbound communication functions beyond repair. In the gateway adapter object, I have purposefully limited all outbound communication to the curl_transaction function, to make this sort of thing easy.

#Comment by Jpostlethwaite (talk | contribs)   17:34, 27 October 2011

I agree with you that we need to keep that separate for production.

I feel that for development, it is necessary to test as close to the heart of the code as possible.

It is key to make sure that connections point to test servers.

I always do this by setting an environment variable in the web server or the CLI:

APPLICATION_ENVIRONMENT = unittesting | localhost | development | production

#Comment by Khorn (WMF) (talk | contribs)   18:00, 27 October 2011

I am totally going to argue with you on this one, particularly if there's any chance that this code could get fired automatically on a commit trigger. If you need to get a response back from them for a test to go through, you're testing their servers more than you're unit testing our internal code, which technically speaking is no longer unit testing. Additionally: It could be catastrophic if somebody somewhere installs this code and misses a setting, or makes one bad commit. Then suddenly we're talking international wire fraud. Yes: This is actually that dangerous. Not just for us, but for others who might install the code and fire it off. It would be infinitely better for all possible involved parties if they actually had to deliberately damage something to get into trouble. Us as well.

#Comment by Jpostlethwaite (talk | contribs)   18:19, 27 October 2011

The way I am doing it now, it is not hitting there servers.

We are only generating the request and looking at it.

#Comment by Jpostlethwaite (talk | contribs)   18:21, 27 October 2011

i do not attempt to connect to GlobalCollect.

We only run:

return $this->buildRequestXML();

#Comment by Jpostlethwaite (talk | contribs)   18:24, 27 October 2011

This is safe and necessary to test.

I have no intention of running: do_transaction().

#Comment by Khorn (WMF) (talk | contribs)   17:01, 27 October 2011

Also: Is this object being used anywhere yet? I see the last time TESTS_ADAPTER_DEFAULT was defined was r100618, prior to this object existing.

#Comment by Jpostlethwaite (talk | contribs)   17:23, 27 October 2011

Yes it is being used to signal which adapter to test.

tests/DonationInterfaceTestCase.php 131: $adapter = isset( $adapter ) ? (string) $adapter : TESTS_ADAPTER_DEFAULT ;

#Comment by Khorn (WMF) (talk | contribs)   17:53, 27 October 2011

Yeah, I see that, but I also see

define( 'TESTS_ADAPTER_DEFAULT', 'GlobalCollectAdapter' );

in TestConfiguration. Shouldn't this point to the test object?

#Comment by Jpostlethwaite (talk | contribs)   20:43, 5 November 2011

This maps to the test adapter.

#Comment by Jpostlethwaite (talk | contribs)   20:43, 5 November 2011

We are not doing unit tests against GlobalCollect, which I believe is the issue with the fixme.

We are testing that the request xml is properly generated for each payment product.

Status & tagging log