19
19
use Magento \Quote \Model \Quote \Address \RateRequestFactory ;
20
20
use Magento \TestFramework \HTTP \AsyncClientInterfaceMock ;
21
21
use PHPUnit \Framework \TestCase ;
22
+ use PHPUnit \Framework \MockObject \MockObject ;
22
23
use Magento \Shipping \Model \Shipment \Request ;
24
+ use Psr \Log \LoggerInterface ;
23
25
24
26
/**
25
27
* Integration tests for Carrier model class
@@ -43,14 +45,32 @@ class CarrierTest extends TestCase
43
45
*/
44
46
private $ config ;
45
47
48
+ /**
49
+ * @var LoggerInterface|MockObject
50
+ */
51
+ private $ loggerMock ;
52
+
53
+ /**
54
+ * @var string[]
55
+ */
56
+ private $ logs = [];
57
+
46
58
/**
47
59
* @inheritDoc
48
60
*/
49
61
protected function setUp (): void
50
62
{
51
- $ this ->carrier = Bootstrap::getObjectManager ()->create (Carrier::class);
52
63
$ this ->httpClient = Bootstrap::getObjectManager ()->get (AsyncClientInterface::class);
53
64
$ this ->config = Bootstrap::getObjectManager ()->get (ReinitableConfigInterface::class);
65
+ $ this ->logs = [];
66
+ $ this ->loggerMock = $ this ->getMockForAbstractClass (LoggerInterface::class);
67
+ $ this ->loggerMock ->method ('debug ' )
68
+ ->willReturnCallback (
69
+ function (string $ message ) {
70
+ $ this ->logs [] = $ message ;
71
+ }
72
+ );
73
+ $ this ->carrier = Bootstrap::getObjectManager ()->create (Carrier::class, ['logger ' => $ this ->loggerMock ]);
54
74
}
55
75
56
76
/**
@@ -136,6 +156,7 @@ public function testCollectFreeRates()
136
156
* @magentoConfigFixture default_store carriers/ups/username user
137
157
* @magentoConfigFixture default_store carriers/ups/password pass
138
158
* @magentoConfigFixture default_store carriers/ups/access_license_number acn
159
+ * @magentoConfigFixture default_store carriers/ups/debug 1
139
160
* @magentoConfigFixture default_store currency/options/allow GBP,USD,EUR
140
161
* @magentoConfigFixture default_store currency/options/base GBP
141
162
*/
@@ -172,6 +193,17 @@ public function testCollectRates(int $negotiable, int $tax, int $responseId, str
172
193
$ rates = $ this ->carrier ->collectRates ($ request )->getAllRates ();
173
194
$ this ->assertEquals ($ price , $ rates [0 ]->getPrice ());
174
195
$ this ->assertEquals ($ method , $ rates [0 ]->getMethod ());
196
+
197
+ $ requestFound = false ;
198
+ foreach ($ this ->logs as $ log ) {
199
+ if (mb_stripos ($ log , 'RatingServiceSelectionRequest ' ) &&
200
+ mb_stripos ($ log , 'RatingServiceSelectionResponse ' )
201
+ ) {
202
+ $ requestFound = true ;
203
+ break ;
204
+ }
205
+ }
206
+ $ this ->assertTrue ($ requestFound );
175
207
}
176
208
177
209
/**
@@ -304,6 +336,7 @@ public function testRequestToShipment(): void
304
336
* @magentoConfigFixture default_store carriers/ups/username user
305
337
* @magentoConfigFixture default_store carriers/ups/password pass
306
338
* @magentoConfigFixture default_store carriers/ups/access_license_number acn
339
+ * @magentoConfigFixture default_store carriers/ups/debug 1
307
340
* @magentoConfigFixture default_store currency/options/allow GBP,USD,EUR
308
341
* @magentoConfigFixture default_store currency/options/base GBP
309
342
*/
0 commit comments