77
88use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
99
10+ /**
11+ * Class ObserverTest
12+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+ */
1014class ObserverTest extends \PHPUnit \Framework \TestCase
1115{
1216 /**
@@ -96,11 +100,11 @@ protected function setUp()
96100 );
97101 }
98102
99- /**
100- * @expectedException \Exception
101- */
102- public function testScheduledGenerateSitemapsThrowsException ()
103+ public function testScheduledGenerateSitemapsSendsExceptionEmail ()
103104 {
105+ $ exception = 'Sitemap Exception ' ;
106+ $ transport = $ this ->createMock (\Magento \Framework \Mail \TransportInterface::class);
107+
104108 $ this ->scopeConfigMock ->expects ($ this ->once ())->method ('isSetFlag ' )->willReturn (true );
105109
106110 $ this ->collectionFactoryMock ->expects ($ this ->once ())
@@ -111,7 +115,55 @@ public function testScheduledGenerateSitemapsThrowsException()
111115 ->method ('getIterator ' )
112116 ->willReturn (new \ArrayIterator ([$ this ->sitemapMock ]));
113117
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 ' );
115167
116168 $ this ->observer ->scheduledGenerateSitemaps ();
117169 }
0 commit comments