From 8269b84b7a9ab831b6596d2331a1f1cc9b31b4d9 Mon Sep 17 00:00:00 2001 From: vagrant Date: Thu, 26 Mar 2020 10:29:45 +0100 Subject: [PATCH 1/4] Expect email notification to send, and simplify setup a bit. --- .../Sitemap/Test/Unit/Model/ObserverTest.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php index 09f5418bbd762..543d9598553cc 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php @@ -64,18 +64,19 @@ class ObserverTest extends \PHPUnit\Framework\TestCase protected function setUp() { - $this->objectManagerMock = $this->getMockBuilder(\Magento\Framework\ObjectManagerInterface::class) - ->getMock(); - $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class) - ->getMock(); + $this->objectManagerMock = $this->createMock( + \Magento\Framework\ObjectManagerInterface::class + ); + $this->scopeConfigMock = $this->createMock( + \Magento\Framework\App\Config\ScopeConfigInterface::class + ); $this->collectionFactoryMock = $this->getMockBuilder( \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory::class )->disableOriginalConstructor() ->setMethods(['create']) ->getMock(); - $this->sitemapCollectionMock = $this->createPartialMock( - \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection::class, - ['getIterator'] + $this->sitemapCollectionMock = $this->createMock( + \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection::class ); $this->sitemapMock = $this->createPartialMock( \Magento\Sitemap\Model\Sitemap::class, @@ -130,6 +131,10 @@ public function testScheduledGenerateSitemapsSendsExceptionEmail() ) ->willReturn('error-recipient@example.com'); + $this->emailNotificationMock->expects($this->once()) + ->method('sendErrors') + ->with(['Sitemap Exception']); + $this->observer->scheduledGenerateSitemaps(); } } From f0b3ab87851b2e19b0a695bf229f2260a90494ad Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Thu, 26 Mar 2020 18:04:55 +0200 Subject: [PATCH 2/4] Fix Static test --- app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php index 543d9598553cc..7430213030f96 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php @@ -11,7 +11,7 @@ use Magento\Store\Model\App\Emulation; /** - * Class ObserverTest + * Class for ObserverTest * * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ From 0d887662aa0e81a40c44a354d3e3a1abaf91fb29 Mon Sep 17 00:00:00 2001 From: Alexander Steshuk Date: Fri, 3 Apr 2020 16:26:04 +0300 Subject: [PATCH 3/4] Format code. --- app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php index 7430213030f96..8ab8cbfb6122b 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php @@ -133,7 +133,7 @@ public function testScheduledGenerateSitemapsSendsExceptionEmail() $this->emailNotificationMock->expects($this->once()) ->method('sendErrors') - ->with(['Sitemap Exception']); + ->with([$exception]); $this->observer->scheduledGenerateSitemaps(); } From a80b84d4eb4ee0c53aa0e717377c80f921caf7c8 Mon Sep 17 00:00:00 2001 From: Slava Mankivski Date: Mon, 13 Apr 2020 13:25:38 -0500 Subject: [PATCH 4/4] Update ObserverTest.php Fixed PHPUnit_Framework_MockObject_MockObject usages --- .../Sitemap/Test/Unit/Model/ObserverTest.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php index 8ab8cbfb6122b..7d2bdcc93b686 100644 --- a/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php +++ b/app/code/Magento/Sitemap/Test/Unit/Model/ObserverTest.php @@ -28,37 +28,37 @@ class ObserverTest extends \PHPUnit\Framework\TestCase private $observer; /** - * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit\Framework\MockObject\MockObject */ private $scopeConfigMock; /** - * @var \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory|\PHPUnit\Framework\MockObject\MockObject */ private $collectionFactoryMock; /** - * @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sitemap\Model\ResourceModel\Sitemap\Collection|\PHPUnit\Framework\MockObject\MockObject */ private $sitemapCollectionMock; /** - * @var \Magento\Sitemap\Model\Sitemap|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Sitemap\Model\Sitemap|\PHPUnit\Framework\MockObject\MockObject */ private $sitemapMock; /** - * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit_Framework_MockObject_MockObject + * @var \Magento\Framework\ObjectManagerInterface|\PHPUnit\Framework\MockObject\MockObject */ private $objectManagerMock; /** - * @var Emulation|\PHPUnit_Framework_MockObject_MockObject + * @var Emulation|\PHPUnit\Framework\MockObject\MockObject */ private $appEmulationMock; /** - * @var EmailNotification|\PHPUnit_Framework_MockObject_MockObject + * @var EmailNotification|\PHPUnit\Framework\MockObject\MockObject */ private $emailNotificationMock;