@@ -27,6 +27,15 @@ class ShipmentSenderTest extends \PHPUnit\Framework\TestCase
27
27
private const OLD_CUSTOMER_EMAIL = 'customer@example.com ' ;
28
28
private const ORDER_EMAIL = 'customer@example.com ' ;
29
29
30
+ /** @var ObjectManagerInterface */
31
+ private $ objectManager ;
32
+
33
+ /** @var Logger */
34
+ private $ logger ;
35
+
36
+ /** @var int */
37
+ private $ minErrorDefaultValue ;
38
+
30
39
/**
31
40
* @var CustomerRepository
32
41
*/
@@ -38,7 +47,17 @@ class ShipmentSenderTest extends \PHPUnit\Framework\TestCase
38
47
protected function setUp (): void
39
48
{
40
49
parent ::setUp ();
41
- $ this ->customerRepository = Bootstrap::getObjectManager ()
50
+
51
+ $ this ->objectManager = Bootstrap::getObjectManager ();
52
+ $ this ->objectManager ->get (\Magento \Framework \App \State::class)->setMode (State::MODE_PRODUCTION );
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
42
61
->get (CustomerRepositoryInterface::class);
43
62
}
44
63
@@ -47,27 +66,19 @@ protected function setUp(): void
47
66
*/
48
67
public function testSend ()
49
68
{
50
- Bootstrap:: getObjectManager () ->get (\Magento \Framework \App \State::class)->setAreaCode ('frontend ' );
51
- $ order = Bootstrap:: getObjectManager () ->create (\Magento \Sales \Model \Order::class);
69
+ $ this -> objectManager ->get (\Magento \Framework \App \State::class)->setAreaCode ('frontend ' );
70
+ $ order = $ this -> objectManager ->create (\Magento \Sales \Model \Order::class);
52
71
$ order ->loadByIncrementId ('100000001 ' );
53
72
$ order ->setCustomerEmail ('customer@example.com ' );
54
73
55
- $ shipment = Bootstrap:: getObjectManager () ->get (ShipmentFactory::class)->create ($ order );
74
+ $ shipment = $ this -> objectManager ->get (ShipmentFactory::class)->create ($ order );
56
75
57
76
$ this ->assertEmpty ($ shipment ->getEmailSent ());
58
77
59
- $ objectManager = Bootstrap::getObjectManager ();
60
- $ logger = $ objectManager ->get (Logger::class);
61
- $ reflection = new \ReflectionClass (get_class ($ logger ));
62
- $ reflectionProperty = $ reflection ->getProperty ('minimumErrorLevel ' );
63
- $ reflectionProperty ->setAccessible (true );
64
- $ reflectionProperty ->setValue ($ logger , 400 );
65
- $ logger ->clearMessages ();
66
- $ orderSender = $ objectManager
78
+ $ orderSender = $ this ->objectManager
67
79
->create (\Magento \Sales \Model \Order \Email \Sender \ShipmentSender::class);
68
- $ objectManager ->get (\Magento \Framework \App \State::class)->setMode (State::MODE_PRODUCTION );
69
80
$ result = $ orderSender ->send ($ shipment , true );
70
- $ this ->assertEmpty ($ logger ->getMessages ());
81
+ $ this ->assertEmpty ($ this -> logger ->getMessages ());
71
82
$ this ->assertTrue ($ result );
72
83
73
84
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -93,6 +104,7 @@ public function testSendWhenCustomerEmailWasModified()
93
104
$ this ->assertEmpty ($ shipment ->getEmailSent ());
94
105
$ result = $ shipmentSender ->send ($ shipment , true );
95
106
107
+ $ this ->assertEmpty ($ this ->logger ->getMessages ());
96
108
$ this ->assertEquals (self ::NEW_CUSTOMER_EMAIL , $ shipmentIdentity ->getCustomerEmail ());
97
109
$ this ->assertTrue ($ result );
98
110
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -114,6 +126,7 @@ public function testSendWhenCustomerEmailWasNotModified()
114
126
$ this ->assertEmpty ($ shipment ->getEmailSent ());
115
127
$ result = $ shipmentSender ->send ($ shipment , true );
116
128
129
+ $ this ->assertEmpty ($ this ->logger ->getMessages ());
117
130
$ this ->assertEquals (self ::OLD_CUSTOMER_EMAIL , $ shipmentIdentity ->getCustomerEmail ());
118
131
$ this ->assertTrue ($ result );
119
132
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -138,6 +151,7 @@ public function testSendWithoutCustomer()
138
151
$ this ->assertEmpty ($ shipment ->getEmailSent ());
139
152
$ result = $ shipmentSender ->send ($ shipment , true );
140
153
154
+ $ this ->assertEmpty ($ this ->logger ->getMessages ());
141
155
$ this ->assertEquals (self ::ORDER_EMAIL , $ shipmentIdentity ->getCustomerEmail ());
142
156
$ this ->assertTrue ($ result );
143
157
$ this ->assertNotEmpty ($ shipment ->getEmailSent ());
@@ -150,17 +164,16 @@ public function testSendWithoutCustomer()
150
164
*/
151
165
public function testPackages ()
152
166
{
153
- $ objectManager = Bootstrap::getObjectManager ();
154
- $ objectManager ->get (\Magento \Framework \App \State::class)->setAreaCode ('frontend ' );
155
- $ order = $ objectManager ->create (\Magento \Sales \Model \Order::class);
167
+ $ this ->objectManager ->get (\Magento \Framework \App \State::class)->setAreaCode ('frontend ' );
168
+ $ order = $ this ->objectManager ->create (\Magento \Sales \Model \Order::class);
156
169
$ order ->loadByIncrementId ('100000001 ' );
157
170
$ order ->setCustomerEmail ('customer@example.com ' );
158
171
$ items = [];
159
172
foreach ($ order ->getItems () as $ item ) {
160
173
$ items [$ item ->getId ()] = $ item ->getQtyOrdered ();
161
174
}
162
175
/** @var \Magento\Sales\Model\Order\Shipment $shipment */
163
- $ shipment = $ objectManager ->get (ShipmentFactory::class)->create ($ order , $ items );
176
+ $ shipment = $ this -> objectManager ->get (ShipmentFactory::class)->create ($ order , $ items );
164
177
$ packages = [['1 ' ], ['2 ' ]];
165
178
$ shipment ->setPackages ($ packages );
166
179
$ this ->assertEquals ($ packages , $ shipment ->getPackages ());
@@ -172,7 +185,7 @@ public function testPackages()
172
185
173
186
private function createShipment (Order $ order ): Shipment
174
187
{
175
- $ shipment = Bootstrap:: getObjectManager () ->create (
188
+ $ shipment = $ this -> objectManager ->create (
176
189
Shipment::class
177
190
);
178
191
$ shipment ->setOrder ($ order );
@@ -206,4 +219,14 @@ private function createShipmentSender(ShipmentIdentity $shipmentIdentity): Shipm
206
219
]
207
220
);
208
221
}
222
+
223
+ /**
224
+ * @inheritdoc
225
+ */
226
+ protected function tearDown (): void
227
+ {
228
+ $ reflectionProperty = new \ReflectionProperty (get_class ($ this ->logger ), 'minimumErrorLevel ' );
229
+ $ reflectionProperty ->setAccessible (true );
230
+ $ reflectionProperty ->setValue ($ this ->logger , $ this ->minErrorDefaultValue );
231
+ }
209
232
}
0 commit comments