7
7
8
8
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
9
9
10
+ /**
11
+ * Class ObserverTest
12
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13
+ */
10
14
class ObserverTest extends \PHPUnit \Framework \TestCase
11
15
{
12
16
/**
@@ -96,11 +100,11 @@ protected function setUp()
96
100
);
97
101
}
98
102
99
- /**
100
- * @expectedException \Exception
101
- */
102
- public function testScheduledGenerateSitemapsThrowsException ()
103
+ public function testScheduledGenerateSitemapsSendsExceptionEmail ()
103
104
{
105
+ $ exception = 'Sitemap Exception ' ;
106
+ $ transport = $ this ->createMock (\Magento \Framework \Mail \TransportInterface::class);
107
+
104
108
$ this ->scopeConfigMock ->expects ($ this ->once ())->method ('isSetFlag ' )->willReturn (true );
105
109
106
110
$ this ->collectionFactoryMock ->expects ($ this ->once ())
@@ -111,7 +115,55 @@ public function testScheduledGenerateSitemapsThrowsException()
111
115
->method ('getIterator ' )
112
116
->willReturn (new \ArrayIterator ([$ this ->sitemapMock ]));
113
117
114
- $ this ->sitemapMock ->expects ($ this ->once ())->method ('generateXml ' )->willThrowException (new \Exception ());
118
+ $ this ->sitemapMock ->expects ($ this ->once ())
119
+ ->method ('generateXml ' )
120
+ ->willThrowException (new \Exception ($ exception ));
121
+
122
+ $ this ->scopeConfigMock ->expects ($ this ->at (1 ))
123
+ ->method ('getValue ' )
124
+ ->with (
125
+ \Magento \Sitemap \Model \Observer::XML_PATH_ERROR_RECIPIENT ,
126
+ \Magento \Store \Model \ScopeInterface::SCOPE_STORE
127
+ )
128
+ ->
willReturn (
'[email protected] ' );
129
+
130
+ $ this ->inlineTranslationMock ->expects ($ this ->once ())
131
+ ->method ('suspend ' );
132
+
133
+ $ this ->transportBuilderMock ->expects ($ this ->once ())
134
+ ->method ('setTemplateIdentifier ' )
135
+ ->will ($ this ->returnSelf ());
136
+
137
+ $ this ->transportBuilderMock ->expects ($ this ->once ())
138
+ ->method ('setTemplateOptions ' )
139
+ ->with ([
140
+ 'area ' => \Magento \Backend \App \Area \FrontNameResolver::AREA_CODE ,
141
+ 'store ' => \Magento \Store \Model \Store::DEFAULT_STORE_ID ,
142
+ ])
143
+ ->will ($ this ->returnSelf ());
144
+
145
+ $ this ->transportBuilderMock ->expects ($ this ->once ())
146
+ ->method ('setTemplateVars ' )
147
+ ->with (['warnings ' => $ exception ])
148
+ ->will ($ this ->returnSelf ());
149
+
150
+ $ this ->transportBuilderMock ->expects ($ this ->once ())
151
+ ->method ('setFrom ' )
152
+ ->will ($ this ->returnSelf ());
153
+
154
+ $ this ->transportBuilderMock ->expects ($ this ->once ())
155
+ ->method ('addTo ' )
156
+ ->will ($ this ->returnSelf ());
157
+
158
+ $ this ->transportBuilderMock ->expects ($ this ->once ())
159
+ ->method ('getTransport ' )
160
+ ->willReturn ($ transport );
161
+
162
+ $ transport ->expects ($ this ->once ())
163
+ ->method ('sendMessage ' );
164
+
165
+ $ this ->inlineTranslationMock ->expects ($ this ->once ())
166
+ ->method ('resume ' );
115
167
116
168
$ this ->observer ->scheduledGenerateSitemaps ();
117
169
}
0 commit comments