@@ -50,10 +50,7 @@ public function testInvalidDobStringThrows(): void
50
50
$ this ->mockAttributeRulesArray (['date_range_min ' => '1980-01-01 ' , 'date_range_max ' => '2000-12-31 ' ]);
51
51
52
52
$ called = false ;
53
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
54
- $ called = true ;
55
- return $ c ;
56
- };
53
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
57
54
58
55
$ this ->expectException (InputException::class);
59
56
$ this ->expectExceptionMessage ('Date of Birth is invalid. ' );
@@ -68,10 +65,7 @@ public function testDobBeforeMinThrows(): void
68
65
$ this ->mockAttributeRulesArray (['date_range_min ' => '1980-01-01 ' , 'date_range_max ' => '2000-12-31 ' ]);
69
66
70
67
$ called = false ;
71
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
72
- $ called = true ;
73
- return $ c ;
74
- };
68
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
75
69
76
70
$ this ->expectException (InputException::class);
77
71
$ this ->expectExceptionMessage ('on or after 1980-01-01 ' );
@@ -86,10 +80,7 @@ public function testDobAfterMaxThrows(): void
86
80
$ this ->mockAttributeRulesArray (['date_range_min ' => '1980-01-01 ' , 'date_range_max ' => '2000-12-31 ' ]);
87
81
88
82
$ called = false ;
89
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
90
- $ called = true ;
91
- return $ c ;
92
- };
83
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
93
84
94
85
$ this ->expectException (InputException::class);
95
86
$ this ->expectExceptionMessage ('on or before 2000-12-31 ' );
@@ -122,10 +113,7 @@ public function testEmptyDobSkipsValidationAndProceeds(): void
122
113
$ this ->mockAttributeRulesArray (['date_range_min ' => '1980-01-01 ' , 'date_range_max ' => '2000-12-31 ' ]);
123
114
124
115
$ called = false ;
125
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
126
- $ called = true ;
127
- return $ c ;
128
- };
116
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
129
117
130
118
$ actual = $ this ->plugin ->aroundSave ($ this ->repo , $ proceed , $ customer , null );
131
119
@@ -144,10 +132,7 @@ public function testRulesAsJsonStringAreUnserialized(): void
144
132
$ this ->json ->expects ($ this ->once ())->method ('unserialize ' )->with ($ json )->willReturn ($ rules );
145
133
146
134
$ called = false ;
147
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
148
- $ called = true ;
149
- return $ c ;
150
- };
135
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
151
136
152
137
$ this ->expectException (InputException::class);
153
138
$ this ->expectExceptionMessage ('on or after 1980-01-01 ' );
@@ -165,10 +150,7 @@ public function testMillisecondRulesBeforeMinThrows(): void
165
150
$ this ->mockAttributeRulesArray (['date_range_min ' => $ minMs , 'date_range_max ' => $ maxMs ]);
166
151
167
152
$ called = false ;
168
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
169
- $ called = true ;
170
- return $ c ;
171
- };
153
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
172
154
173
155
$ this ->expectException (InputException::class);
174
156
$ this ->expectExceptionMessage ('on or after 1980-01-01 ' );
@@ -184,10 +166,7 @@ public function testDobAsMillisecondTimestampThrowsAgainstStringRule(): void
184
166
$ this ->mockAttributeRulesArray (['date_range_min ' => '1980-01-01 ' , 'date_range_max ' => '2000-12-31 ' ]);
185
167
186
168
$ called = false ;
187
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
188
- $ called = true ;
189
- return $ c ;
190
- };
169
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
191
170
192
171
$ this ->expectException (InputException::class);
193
172
$ this ->expectExceptionMessage ('on or after 1980-01-01 ' );
@@ -274,10 +253,7 @@ public function testFallbackToGetValidateRulesArrayIsUsed(): void
274
253
]);
275
254
276
255
$ called = false ;
277
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
278
- $ called = true ;
279
- return $ c ;
280
- };
256
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
281
257
282
258
$ this ->expectException (InputException::class);
283
259
$ this ->expectExceptionMessage ('on or after 1980-01-01 ' );
@@ -324,10 +300,7 @@ public function testDobZeroEpochInvalidThrows(): void
324
300
]);
325
301
326
302
$ called = false ;
327
- $ proceed = function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
328
- $ called = true ;
329
- return $ c ;
330
- };
303
+ $ proceed = $ this ->proceedPlugin ($ called , $ customer );
331
304
332
305
$ this ->expectException (InputException::class);
333
306
$ this ->expectExceptionMessage ('Date of Birth is invalid. ' );
@@ -336,6 +309,22 @@ public function testDobZeroEpochInvalidThrows(): void
336
309
$ this ->assertFalse ($ called );
337
310
}
338
311
312
+ /**
313
+ * Create a proceed closure that marks $called and returns either the given $result or the original $customer.
314
+ *
315
+ * @param bool $called Will be set to true when proceed is invoked
316
+ * @param CustomerInterface|null $result Optional value to return instead of $customer
317
+ * @return callable
318
+ * @SuppressWarnings(PHPMD.UnusedFormalParameter)
319
+ */
320
+ private function proceedPlugin (bool &$ called , ?CustomerInterface $ result = null ): callable
321
+ {
322
+ return function (CustomerInterface $ c , $ hash = null ) use (&$ called ) {
323
+ $ called = true ;
324
+ return $ c ;
325
+ };
326
+ }
327
+
339
328
/**
340
329
* Create a customer mock with a specific DOB value.
341
330
*
0 commit comments