12
12
use Magento \Sales \Model \Order \Shipment ;
13
13
use Magento \Sales \Model \Order \ShipmentFactory ;
14
14
use Magento \TestFramework \Helper \Bootstrap ;
15
- use Magento \Framework \App \State ;
16
- use Magento \TestFramework \ErrorLog \Logger ;
17
15
18
16
/**
19
17
* @magentoAppArea frontend
20
18
*
21
19
* @deprecated since ShipmentSender is deprecated
22
20
* @see \Magento\Sales\Model\Order\Email\Sender\ShipmentSender
23
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
24
21
*/
25
22
class ShipmentSenderTest extends \PHPUnit \Framework \TestCase
26
23
{
27
24
private const NEW_CUSTOMER_EMAIL = 'new.customer@example.com ' ;
28
25
private const OLD_CUSTOMER_EMAIL = 'customer@example.com ' ;
29
26
private const ORDER_EMAIL = 'customer@example.com ' ;
30
27
31
- /** @var ObjectManagerInterface */
32
- private $ objectManager ;
33
-
34
- /** @var Logger */
35
- private $ logger ;
36
-
37
- /** @var int */
38
- private $ minErrorDefaultValue ;
39
-
40
28
/**
41
29
* @var CustomerRepository
42
30
*/
@@ -48,16 +36,7 @@ class ShipmentSenderTest extends \PHPUnit\Framework\TestCase
48
36
protected function setUp (): void
49
37
{
50
38
parent ::setUp ();
51
-
52
- $ this ->objectManager = Bootstrap::getObjectManager ();
53
- $ this ->logger = $ this ->objectManager ->get (Logger::class);
54
- $ reflection = new \ReflectionClass (get_class ($ this ->logger ));
55
- $ reflectionProperty = $ reflection ->getProperty ('minimumErrorLevel ' );
56
- $ reflectionProperty ->setAccessible (true );
57
- $ this ->minErrorDefaultValue = $ reflectionProperty ->getValue ($ this ->logger );
58
- $ reflectionProperty ->setValue ($ this ->logger , 400 );
59
- $ this ->logger ->clearMessages ();
60
- $ this ->customerRepository = $ this ->objectManager
39
+ $ this ->customerRepository = Bootstrap::getObjectManager ()
61
40
->get (CustomerRepositoryInterface::class);
62
41
}
63
42
@@ -66,24 +45,19 @@ protected function setUp(): void
66
45
*/
67
46
public function testSend ()
68
47
{
69
- $ this -> objectManager -> get (State::class)->setAreaCode ('frontend ' );
70
- $ order = $ this -> objectManager ->create (\Magento \Sales \Model \Order::class);
48
+ Bootstrap:: getObjectManager ()-> get (\ Magento \ Framework \ App \ State::class)->setAreaCode ('frontend ' );
49
+ $ order = Bootstrap:: getObjectManager () ->create (\Magento \Sales \Model \Order::class);
71
50
$ order ->loadByIncrementId ('100000001 ' );
72
51
$ order ->setCustomerEmail ('customer@example.com ' );
73
52
74
- $ shipment = $ this -> objectManager ->get (ShipmentFactory::class)->create ($ order );
53
+ $ shipment = Bootstrap:: getObjectManager () ->get (ShipmentFactory::class)->create ($ order );
75
54
76
55
$ this ->assertEmpty ($ shipment ->getEmailSent ());
77
56
78
- $ orderSender = $ this -> objectManager
57
+ $ orderSender = Bootstrap:: getObjectManager ()
79
58
->create (\Magento \Sales \Model \Order \Email \Sender \ShipmentSender::class);
80
59
$ result = $ orderSender ->send ($ shipment , true );
81
- $ this ->assertFalse (
82
- array_search (
83
- 'Environment emulation nesting is not allowed. ' ,
84
- array_column ($ this ->logger ->getMessages (), 'message ' )
85
- )
86
- );
60
+
87
61
$ this ->assertTrue ($ result );
88
62
89
63
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -109,12 +83,6 @@ public function testSendWhenCustomerEmailWasModified()
109
83
$ this ->assertEmpty ($ shipment ->getEmailSent ());
110
84
$ result = $ shipmentSender ->send ($ shipment , true );
111
85
112
- $ this ->assertFalse (
113
- array_search (
114
- 'Environment emulation nesting is not allowed. ' ,
115
- array_column ($ this ->logger ->getMessages (), 'message ' )
116
- )
117
- );
118
86
$ this ->assertEquals (self ::NEW_CUSTOMER_EMAIL , $ shipmentIdentity ->getCustomerEmail ());
119
87
$ this ->assertTrue ($ result );
120
88
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -136,12 +104,6 @@ public function testSendWhenCustomerEmailWasNotModified()
136
104
$ this ->assertEmpty ($ shipment ->getEmailSent ());
137
105
$ result = $ shipmentSender ->send ($ shipment , true );
138
106
139
- $ this ->assertFalse (
140
- array_search (
141
- 'Environment emulation nesting is not allowed. ' ,
142
- array_column ($ this ->logger ->getMessages (), 'message ' )
143
- )
144
- );
145
107
$ this ->assertEquals (self ::OLD_CUSTOMER_EMAIL , $ shipmentIdentity ->getCustomerEmail ());
146
108
$ this ->assertTrue ($ result );
147
109
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -166,12 +128,6 @@ public function testSendWithoutCustomer()
166
128
$ this ->assertEmpty ($ shipment ->getEmailSent ());
167
129
$ result = $ shipmentSender ->send ($ shipment , true );
168
130
169
- $ this ->assertFalse (
170
- array_search (
171
- 'Environment emulation nesting is not allowed. ' ,
172
- array_column ($ this ->logger ->getMessages (), 'message ' )
173
- )
174
- );
175
131
$ this ->assertEquals (self ::ORDER_EMAIL , $ shipmentIdentity ->getCustomerEmail ());
176
132
$ this ->assertTrue ($ result );
177
133
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -184,16 +140,17 @@ public function testSendWithoutCustomer()
184
140
*/
185
141
public function testPackages ()
186
142
{
187
- $ this ->objectManager ->get (State::class)->setAreaCode ('frontend ' );
188
- $ order = $ this ->objectManager ->create (\Magento \Sales \Model \Order::class);
143
+ $ objectManager = Bootstrap::getObjectManager ();
144
+ $ objectManager ->get (\Magento \Framework \App \State::class)->setAreaCode ('frontend ' );
145
+ $ order = $ objectManager ->create (\Magento \Sales \Model \Order::class);
189
146
$ order ->loadByIncrementId ('100000001 ' );
190
147
$ order ->setCustomerEmail ('customer@example.com ' );
191
148
$ items = [];
192
149
foreach ($ order ->getItems () as $ item ) {
193
150
$ items [$ item ->getId ()] = $ item ->getQtyOrdered ();
194
151
}
195
152
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
196
- $ shipment = $ this -> objectManager ->get (ShipmentFactory::class)->create ($ order , $ items );
153
+ $ shipment = $ objectManager ->get (ShipmentFactory::class)->create ($ order , $ items );
197
154
$ packages = [['1 ' ], ['2 ' ]];
198
155
$ shipment ->setPackages ($ packages );
199
156
$ this ->assertEquals ($ packages , $ shipment ->getPackages ());
@@ -205,7 +162,7 @@ public function testPackages()
205
162
206
163
private function createShipment (Order $ order ): Shipment
207
164
{
208
- $ shipment = $ this -> objectManager ->create (
165
+ $ shipment = Bootstrap:: getObjectManager () ->create (
209
166
Shipment::class
210
167
);
211
168
$ shipment ->setOrder ($ order );
@@ -239,14 +196,4 @@ private function createShipmentSender(ShipmentIdentity $shipmentIdentity): Shipm
239
196
]
240
197
);
241
198
}
242
-
243
- /**
244
- * @inheritdoc
245
- */
246
- protected function tearDown (): void
247
- {
248
- $ reflectionProperty = new \ReflectionProperty (get_class ($ this ->logger ), 'minimumErrorLevel ' );
249
- $ reflectionProperty ->setAccessible (true );
250
- $ reflectionProperty ->setValue ($ this ->logger , $ this ->minErrorDefaultValue );
251
- }
252
199
}
0 commit comments