Skip to content

Commit eabdf09

Browse files
authored
ENGCOM-7209: Sitemap Observer Unit Test improvement: Expect email notification to send, and simplify setup a bit. #27448
2 parents db8c73b + 2bb6ed3 commit eabdf09

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Store\Model\App\Emulation;
1212

1313
/**
14-
* Class ObserverTest
14+
* Class for ObserverTest
1515
*
1616
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1717
*/
@@ -28,54 +28,55 @@ class ObserverTest extends \PHPUnit\Framework\TestCase
2828
private $observer;
2929

3030
/**
31-
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
31+
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit\Framework\MockObject\MockObject
3232
*/
3333
private $scopeConfigMock;
3434

3535
/**
36-
* @var \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
36+
* @var \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory|\PHPUnit\Framework\MockObject\MockObject
3737
*/
3838
private $collectionFactoryMock;
3939

4040
/**
41-
* @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection|\PHPUnit_Framework_MockObject_MockObject
41+
* @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection|\PHPUnit\Framework\MockObject\MockObject
4242
*/
4343
private $sitemapCollectionMock;
4444

4545
/**
46-
* @var \Magento\Sitemap\Model\Sitemap|\PHPUnit_Framework_MockObject_MockObject
46+
* @var \Magento\Sitemap\Model\Sitemap|\PHPUnit\Framework\MockObject\MockObject
4747
*/
4848
private $sitemapMock;
4949

5050
/**
51-
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject
51+
* @var \Magento\Framework\ObjectManagerInterface|\PHPUnit\Framework\MockObject\MockObject
5252
*/
5353
private $objectManagerMock;
5454

5555
/**
56-
* @var Emulation|\PHPUnit_Framework_MockObject_MockObject
56+
* @var Emulation|\PHPUnit\Framework\MockObject\MockObject
5757
*/
5858
private $appEmulationMock;
5959

6060
/**
61-
* @var EmailNotification|\PHPUnit_Framework_MockObject_MockObject
61+
* @var EmailNotification|\PHPUnit\Framework\MockObject\MockObject
6262
*/
6363
private $emailNotificationMock;
6464

6565
protected function setUp()
6666
{
67-
$this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class)
68-
->getMock();
69-
$this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
70-
->getMock();
67+
$this->objectManagerMock = $this->createMock(
68+
\Magento\Framework\ObjectManagerInterface::class
69+
);
70+
$this->scopeConfigMock = $this->createMock(
71+
\Magento\Framework\App\Config\ScopeConfigInterface::class
72+
);
7173
$this->collectionFactoryMock = $this->getMockBuilder(
7274
\Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory::class
7375
)->disableOriginalConstructor()
7476
->setMethods(['create'])
7577
->getMock();
76-
$this->sitemapCollectionMock = $this->createPartialMock(
77-
\Magento\Sitemap\Model\ResourceModel\Sitemap\Collection::class,
78-
['getIterator']
78+
$this->sitemapCollectionMock = $this->createMock(
79+
\Magento\Sitemap\Model\ResourceModel\Sitemap\Collection::class
7980
);
8081
$this->sitemapMock = $this->createPartialMock(
8182
\Magento\Sitemap\Model\Sitemap::class,
@@ -130,6 +131,10 @@ public function testScheduledGenerateSitemapsSendsExceptionEmail()
130131
)
131132
->willReturn('[email protected]');
132133

134+
$this->emailNotificationMock->expects($this->once())
135+
->method('sendErrors')
136+
->with([$exception]);
137+
133138
$this->observer->scheduledGenerateSitemaps();
134139
}
135140
}

0 commit comments

Comments
 (0)