Completed
Pull Request — master (#649)
by Jeroen De
50:49
created

SerializedDataHandlingTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 308
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 6
dl 0
loc 308
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testDataFieldOfDonationIsInteractedWithCorrectly() 0 11 1
B donationDataProvider() 0 271 1
A storeDonation() 0 9 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\DonatingContext\Tests\Integration\DataAccess;
6
7
use Doctrine\ORM\EntityManager;
8
use WMDE\Fundraising\Entities\Donation;
9
use WMDE\Fundraising\Frontend\DonatingContext\DataAccess\DoctrineDonationRepository;
10
use WMDE\Fundraising\Frontend\DonatingContext\Domain\Repositories\DonationRepository;
11
use WMDE\Fundraising\Frontend\Tests\TestEnvironment;
12
13
/**
14
 * @licence GNU GPL v2+
15
 * @author Kai Nissen < [email protected] >
16
 */
17
class SerializedDataHandlingTest extends \PHPUnit_Framework_TestCase {
18
19
	/** @var EntityManager */
20
	private $entityManager;
21
22
	/** @var DonationRepository */
23
	private $repository;
24
25
	public function setUp() {
26
		$this->entityManager = TestEnvironment::newInstance()->getFactory()->getEntityManager();
27
	}
28
29
	/** @dataProvider donationDataProvider */
30
	public function testDataFieldOfDonationIsInteractedWithCorrectly( $paymentType, $data ) {
31
		$this->repository = new DoctrineDonationRepository( $this->entityManager );
32
		$this->storeDonation( $paymentType, $data );
33
34
		$donation = $this->repository->getDonationById( 1 );
35
		$this->repository->storeDonation( $donation );
0 ignored issues
show
Bug introduced by
It seems like $donation defined by $this->repository->getDonationById(1) on line 34 can be null; however, WMDE\Fundraising\Fronten...sitory::storeDonation() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
36
37
		/** @var Donation $dd */
38
		$dd = $this->entityManager->find( Donation::class, 1 );
39
		$this->assertEquals( $data, $dd->getDecodedData() );
40
	}
41
42
	public function donationDataProvider() {
43
		return [
44
			[
45
				'UEB',
46
				[
47
					'id' => 1839605,
48
					'betrag' => '24.00',
49
					'periode' => 12,
50
					'anrede' => 'Herr',
51
					'titel' => '',
52
					'vorname' => 'Max',
53
					'nachname' => 'Muster',
54
					'plz' => '12345',
55
					'ort' => 'Smalltown',
56
					'country' => 'DE',
57
					'strasse' => 'Erlenkamp 12',
58
					'email' => '[email protected]',
59
					'eintrag' => 'anonym',
60
					'kommentar' => null,
61
					'info' => 0,
62
					'adresstyp' => 'person',
63
					'dob' => null,
64
					'phone' => null,
65
					'source' => 'de.wikipedia.org',
66
					'tracking' => 'dewiki/wikipedia:spenden',
67
					'confirmationPage' => '10h16 Bestätigung-UEB',
68
					'utoken' => '03a448b5ceafb19b954d25688a72973b002ba012',
69
					'uexpiry' => '2016-05-17 15:42:02',
70
					'layout' => 'form=10h16_Form1',
71
					'user_agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0',
72
					'log' => [
73
						'2016-05-17 11:42:02' => 'ueb-code generated (1 tries in 0.02 secs)',
74
					],
75
					'name' => 'Max Muster',
76
77
					// these fields did not exist in the original data set
78
					'skin' => '',
79
					'color' => '',
80
					'firma' => '',
81
82
					// these values were stored as strings
83
					'impCount' => 0,
84
					'bImpCount' => 0,
85
86
					'token' => 'cdd4e95145fb74cb87d7dab8f1e88599'
87
				]
88
			],
89
			[
90
				'BEZ',
91
				[
92
					'id' => '1839609',
93
					'betrag' => '20.00',
94
					'periode' => 0,
95
					'anrede' => 'Herr',
96
					'titel' => '',
97
					'vorname' => 'Max',
98
					'nachname' => 'Muster',
99
					'plz' => '12345',
100
					'ort' => 'Smalltown',
101
					'country' => 'DE',
102
					'strasse' => 'Erlenkamp 12',
103
					'email' => '[email protected]',
104
					'eintrag' => 'anonym',
105
					'kommentar' => null,
106
					'info' => 1,
107
					'adresstyp' => 'person',
108
					'dob' => null,
109
					'phone' => null,
110
					'source' => 'de.wikipedia.org',
111
					'tracking' => 'dewiki/wikipedia:spenden',
112
					'confirmationPage' => '10h16 Bestätigung-BEZ',
113
					'utoken' => 'ec7c3e8ae5413efe76a3e497455bae9841a85c01',
114
					'uexpiry' => '2038-05-17 15:58:53',
115
					'layout' => 'form=10h16_Form1',
116
					'user_agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) ' .
117
						'Chrome/50.0.2661.102 Safari/537.36',
118
					'bankname' => 'Testbank',
119
					'bic' => 'INGDDEFFXXX',
120
					'iban' => 'DE12500105170648489890',
121
					'konto' => '0648489890',
122
					'blz' => '50010517',
123
					'log' => [
124
						'2016-05-17 11:59:21' => 'sepa-mandat confirmed',
125
					],
126
					'name' => 'Max Muster',
127
					'token' => 'ec7c3e8ae5413efe76a3e497455bae9841a85c01',
128
					'firma' => '',
129
					'skin' => '',
130
					'color' => '',
131
132
					// these values were stored as strings
133
					'impCount' => 0,
134
					'bImpCount' => 0,
135
				],
136
			],
137
			[
138
				'MCP',
139
				[
140
					'id' => '1839659',
141
					'betrag' => '5.00',
142
					'periode' => 0,
143
					'anrede' => 'Herr',
144
					'titel' => '',
145
					'vorname' => 'Max',
146
					'nachname' => 'Muster',
147
					'plz' => '12345',
148
					'ort' => 'Smalltown',
149
					'country' => 'DE',
150
					'strasse' => 'Erlenkamp 12',
151
					'email' => '[email protected]',
152
					'eintrag' => 'anonym',
153
					'kommentar' => null,
154
					'info' => 0,
155
					'adresstyp' => 'person',
156
					'dob' => null,
157
					'phone' => null,
158
					'source' => 'de.wikipedia.org',
159
					'tracking' => 'dewiki/wikipedia:spenden',
160
					'confirmationPage' => '10h16 Bestätigung',
161
					'utoken' => '6daf07db933ebe146e4596261ca8d5f27e8e2170',
162
					'uexpiry' => '2016-05-17 19:35:14',
163
					'layout' => 'form=10h16_Form1',
164
					'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; rv:46.0) Gecko/20100101 Firefox/46.0',
165
					'ext_payment_id' => 'spenden.wikimedia.de-IDn24btga9au',
166
					'ext_payment_status' => 'processed',
167
					'ext_payment_account' => 'bc11c979141b208631145ce6f211ab0cdf19b92e',
168
					'ext_payment_type' => 'billing',
169
					'ext_payment_timestamp' => '2016-05-17T15:36:22+02:00',
170
					'mcp_amount' => '5.00',
171
					'mcp_currency' => 'EUR',
172
					'mcp_country' => 'DE',
173
					'mcp_auth' => '542e6b75f5718429aad79c5f0faaed16',
174
					'mcp_title' => 'Ihre Spende an Wikipedia',
175
					'mcp_sessionid' => 'CC6433ad374048307966bb62230246113042e4fd',
176
					'mcp_cc_expiry_date' => '12/2038',
177
					'log' => [
178
						'2016-05-17 15:36:22' => 'mcp_handler: booked'
179
					],
180
					'name' => 'Max Muster',
181
182
					// these fields did not exist in the original data set
183
					'skin' => '',
184
					'color' => '',
185
					'firma' => '',
186
187
					// these values were stored as strings
188
					'impCount' => 0,
189
					'bImpCount' => 0,
190
191
					'token' => 'cdd4e95145fb74cb87d7dab8f1e88599'
192
				]
193
			],
194
			[
195
				'PPL',
196
				[
197
					'id' => null,
198
					'betrag' => '10.00',
199
					'periode' => 0,
200
					'anrede' => '',
201
					'titel' => '',
202
					'vorname' => 'Max',
203
					'nachname' => 'Muster',
204
					'plz' => '12345',
205
					'ort' => 'Smalltown',
206
					'country' => 'DE',
207
					'strasse' => 'Erlenkamp 12',
208
					'email' => '[email protected]',
209
					'eintrag' => 'anonym',
210
					'kommentar' => null,
211
					'info' => 0,
212
					'adresstyp' => 'person',
213
					'dob' => null,
214
					'phone' => null,
215
					'source' => 'web',
216
					'utoken' => '0e54c50d821f72684ee0f40c6cf4597a07971e02',
217
					'uexpiry' => '2016-05-17 18:10:35',
218
					'layout' => '',
219
					'ext_payment_id' => '72171T32A6H345906',
220
					'ext_subscr_id' => 'I-DYP3HRBE7WUA',
221
					'ext_payment_status' => 'Completed/subscr_payment',
222
					'ext_payment_account' => 'QEEMF34KV3ECL',
223
					'ext_payment_type' => 'instant',
224
					'ext_payment_timestamp' => '05:10:30 May 17, 2016 PDT',
225
					'paypal_payer_id' => 'QEEMF34KV3ECL',
226
					'paypal_subscr_id' => 'I-DYP3HRBE7WUA',
227
					'paypal_payer_status' => 'verified',
228
					'paypal_first_name' => 'Max',
229
					'paypal_last_name' => 'Muster',
230
					'paypal_mc_gross' => '10.00',
231
					'paypal_mc_currency' => 'EUR',
232
					'paypal_mc_fee' => '0.47',
233
					'user_agent' => 'PayPal IPN ( https://www.paypal.com/ipn )',
234
					'name' => 'Max Muster',
235
236
					// these fields did not exist in the original data set
237
					'skin' => '',
238
					'color' => '',
239
					'tracking' => '',
240
					'firma' => '',
241
					'paypal_settle_amount' => '1.23',
242
					'paypal_address_name' => 'Max Muster',
243
					'paypal_address_status' => 'unconfirmed',
244
245
					// these values were stored as strings
246
					'impCount' => 0,
247
					'bImpCount' => 0,
248
249
					'token' => 'cdd4e95145fb74cb87d7dab8f1e88599'
250
				]
251
			],
252
			[
253
				'PPL',
254
				[
255
					'id' => '1839597',
256
					'betrag' => '24.00',
257
					'periode' => 12,
258
					'anrede' => 'Herr',
259
					'country' => 'DE',
260
					'eintrag' => 'anonym',
261
					'kommentar' => null,
262
					'info' => 0,
263
					'adresstyp' => 'person',
264
					'source' => 'de.wikipedia.org',
265
					'tracking' => 'de.wikipedia.org/sidebar',
266
					'utoken' => '0463f826b5bf17b298f198c327f54f2557af60bf',
267
					'uexpiry' => '2016-05-16 23:22:06',
268
					'layout' => 'form=10h16_Form1',
269
					'user_agent' => 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko',
270
					'ext_payment_id' => 'V84052263707282L2',
271
					'ext_subscr_id' => 'I-RU6JNJC1UV0E',
272
					'ext_payment_status' => 'Completed/subscr_payment',
273
					'ext_payment_account' => 'AVSBBESGSB8H8',
274
					'ext_payment_type' => 'instant',
275
					'ext_payment_timestamp' => '10:23:09 May 16, 2016 PDT',
276
					'paypal_payer_id' => 'AVSBBESGSB8H8',
277
					'paypal_subscr_id' => 'I-RU6JNJC1UV0E',
278
					'paypal_payer_status' => 'verified',
279
					'paypal_mc_gross' => '24.00',
280
					'paypal_mc_currency' => 'EUR',
281
					'paypal_mc_fee' => '0.64',
282
					'log' => [
283
						'2016-05-16 19:23:16' => 'paypal_handler: booked'
284
					],
285
					'name' => 'Max Muster',
286
					'strasse' => 'Erlenkamp 12',
287
					'ort' => 'Smalltown',
288
					'plz' => '12345',
289
					'titel' => '',
290
					'email' => '[email protected]',
291
					'vorname' => 'Max',
292
					'nachname' => 'Muster',
293
					'paypal_first_name' => 'Max',
294
					'paypal_last_name' => 'Muster',
295
296
					// these fields did not exist in the original data
297
					'skin' => '',
298
					'color' => '',
299
					'firma' => '',
300
					'paypal_settle_amount' => '1.23',
301
					'paypal_address_name' => 'Max Muster',
302
					'paypal_address_status' => 'unconfirmed',
303
304
					// these values were stored as strings
305
					'impCount' => 0,
306
					'bImpCount' => 0,
307
308
					'token' => 'cdd4e95145fb74cb87d7dab8f1e88599'
309
				]
310
			]
311
		];
312
	}
313
314
	private function storeDonation( string $paymentType, array $data ) {
315
		$dd = new Donation();
316
		$dd->setDonorEmail( '[email protected]' );
317
		$dd->setAmount( '1.00' );
318
		$dd->setPaymentType( $paymentType );
319
		$dd->encodeAndSetData( $data );
320
		$this->entityManager->persist( $dd );
321
		$this->entityManager->flush();
322
	}
323
324
}
325