Issues (3877)

ProductBecomeAvailableNotificationSenderTest.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerTest\Zed\AvailabilityNotification\Business\Notification;
9
10
use Codeception\Test\Unit;
11
use Generated\Shared\Transfer\AvailabilityNotificationSubscriptionCollectionTransfer;
12
use Generated\Shared\Transfer\MailTransfer;
13
use Generated\Shared\Transfer\StoreTransfer;
14
use Spryker\Zed\AvailabilityNotification\Business\Notification\ProductBecomeAvailableNotificationSender;
15
use Spryker\Zed\AvailabilityNotification\Business\Product\ProductAttributeFinderInterface;
16
use Spryker\Zed\AvailabilityNotification\Business\Subscription\UrlGeneratorInterface;
17
use Spryker\Zed\AvailabilityNotification\Dependency\Facade\AvailabilityNotificationToMailFacadeInterface;
18
use Spryker\Zed\AvailabilityNotification\Dependency\Facade\AvailabilityNotificationToProductFacadeInterface;
19
use Spryker\Zed\AvailabilityNotification\Persistence\AvailabilityNotificationRepositoryInterface;
20
use SprykerTest\Zed\AvailabilityNotification\AvailabilityNotificationBusinessTester;
21
22
/**
23
 * Auto-generated group annotations
24
 *
25
 * @group SprykerTest
26
 * @group Zed
27
 * @group AvailabilityNotification
28
 * @group Business
29
 * @group Notification
30
 * @group ProductBecomeAvailableNotificationSenderTest
31
 * Add your own group annotations below this line
32
 */
33
class ProductBecomeAvailableNotificationSenderTest extends Unit
34
{
35
    /**
36
     * @var \SprykerTest\Zed\AvailabilityNotification\AvailabilityNotificationBusinessTester
37
     */
38
    protected AvailabilityNotificationBusinessTester $tester;
39
40
    /**
41
     * @return void
42
     */
43
    public function testSendNotificationSendsMailTransferExpandedWithStoreName(): void
44
    {
45
        //Arrange
46
        $availabilityNotificationDataTransfer = $this->tester
47
            ->haveAvailabilityNotificationDataTransfer($this->tester->haveProduct())
48
            ->setStore($this->tester->haveStore());
49
50
        //Assert
51
        $mailFacadeMock = $this->createMailFacadeMock();
52
        $mailFacadeMock
53
            ->expects($this->once())
0 ignored issues
show
The method expects() does not exist on Spryker\Zed\Availability...onToMailFacadeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            ->/** @scrutinizer ignore-call */ 
54
              expects($this->once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
            ->method('handleMail')
55
            ->with($this->callback(function (MailTransfer $mailTransfer) use ($availabilityNotificationDataTransfer) {
56
                return $mailTransfer->getStoreName() === $availabilityNotificationDataTransfer->getStore()->getName();
57
            }));
58
59
        //Act
60
        $productBecomeAvailabilityNotificationSubscriptionSender = new ProductBecomeAvailableNotificationSender(
61
            $mailFacadeMock,
62
            $this->createProductFacadeMock(),
63
            $this->createUrlGeneratorMock(),
64
            $this->createAvailabilityNotificationRepositoryMock(),
65
            $this->createProductAttributeFinderMock(),
66
        );
67
        $productBecomeAvailabilityNotificationSubscriptionSender->send($availabilityNotificationDataTransfer);
68
    }
69
70
    /**
71
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\AvailabilityNotification\Dependency\Facade\AvailabilityNotificationToMailFacadeInterface
72
     */
73
    protected function createMailFacadeMock(): AvailabilityNotificationToMailFacadeInterface
74
    {
75
        return $this->createMock(AvailabilityNotificationToMailFacadeInterface::class);
76
    }
77
78
    /**
79
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\AvailabilityNotification\Dependency\Facade\AvailabilityNotificationToProductFacadeInterface
80
     */
81
    protected function createProductFacadeMock(): AvailabilityNotificationToProductFacadeInterface
82
    {
83
        $productFacadeMock = $this->createMock(AvailabilityNotificationToProductFacadeInterface::class);
84
        $productFacadeMock->expects($this->once())
85
            ->method('getProductConcrete')
86
            ->willReturn($this->tester->haveProduct());
87
88
        return $productFacadeMock;
89
    }
90
91
    /**
92
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\AvailabilityNotification\Business\Subscription\UrlGeneratorInterface
93
     */
94
    protected function createUrlGeneratorMock(): UrlGeneratorInterface
95
    {
96
        return $this->createMock(UrlGeneratorInterface::class);
97
    }
98
99
    /**
100
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\AvailabilityNotification\Business\Product\ProductAttributeFinderInterface
101
     */
102
    protected function createProductAttributeFinderMock(): ProductAttributeFinderInterface
103
    {
104
        return $this->createMock(ProductAttributeFinderInterface::class);
105
    }
106
107
    /**
108
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\AvailabilityNotification\Persistence\AvailabilityNotificationRepositoryInterface
109
     */
110
    protected function createAvailabilityNotificationRepositoryMock(): AvailabilityNotificationRepositoryInterface
111
    {
112
        /*
113
         * Needed for haveAvailabilityNotificationSubscription helper method that uses facade that is called in Gateway context.
114
         */
115
        $this->tester->addCurrentStore($this->tester->haveStore([StoreTransfer::NAME => $this->tester::DEFAULT_STORE_NAME]));
116
        $availabilityNotificationRepositoryMock = $this->createMock(AvailabilityNotificationRepositoryInterface::class);
117
        $availabilityNotificationRepositoryMock->expects($this->once())
118
            ->method('getAvailabilityNotifications')
119
            ->willReturn((new AvailabilityNotificationSubscriptionCollectionTransfer())
120
                ->addAvailabilityNotificationSubscription(
121
                    $this->tester->haveAvailabilityNotificationSubscription(
122
                        $this->tester->haveProduct(),
123
                    ),
124
                ));
125
        $this->tester->removeCurrentStore();
126
127
        return $availabilityNotificationRepositoryMock;
128
    }
129
}
130