InitializeProductExportMessageTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 23
c 0
b 0
f 0
dl 0
loc 43
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testInitializeProductExportMessageIsSuccessfullyHandled() 0 33 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace PyzTest\Zed\MessageBroker\MessageHandlers\Product\Communication;
11
12
use Codeception\Test\Unit;
13
use Generated\Shared\Transfer\EventEntityTransfer;
14
use Generated\Shared\Transfer\InitializeProductExportTransfer;
15
use PyzTest\Zed\MessageBroker\ProductCommunicationTester;
16
use Spryker\Zed\Product\Business\ProductBusinessFactory;
17
use Spryker\Zed\Product\Dependency\Facade\ProductToEventInterface;
18
use Spryker\Zed\Product\Dependency\ProductEvents;
19
use Spryker\Zed\Product\ProductDependencyProvider;
20
21
/**
22
 * Auto-generated group annotations
23
 *
24
 * @group PyzTest
25
 * @group Zed
26
 * @group MessageBroker
27
 * @group MessageHandlers
28
 * @group Product
29
 * @group Communication
30
 * @group InitializeProductExportMessageTest
31
 * Add your own group annotations below this line
32
 */
33
class InitializeProductExportMessageTest extends Unit
34
{
35
    /**
36
     * @var \PyzTest\Zed\MessageBroker\ProductCommunicationTester
37
     */
38
    protected ProductCommunicationTester $tester;
39
40
    /**
41
     * @return void
42
     */
43
    public function testInitializeProductExportMessageIsSuccessfullyHandled(): void
44
    {
45
        // Arrange
46
        $eventFacadeMock = $this->createMock(ProductToEventInterface::class);
47
        $this->tester->setDependency(
48
            ProductDependencyProvider::FACADE_EVENT,
49
            $eventFacadeMock,
50
            ProductBusinessFactory::class,
51
        );
52
        $this->tester->haveFullProduct();
53
        $channelName = 'product-commands';
54
55
        // Assert
56
        $eventFacadeMock->expects($this->atLeastOnce())->method('triggerBulk')->with(
57
            $this->identicalTo(ProductEvents::PRODUCT_CONCRETE_EXPORT),
58
            $this->callback(function (array $transfers) {
59
                $this->assertIsArray($transfers);
60
                $this->assertGreaterThanOrEqual(1, count($transfers));
61
                $this->assertInstanceOf(EventEntityTransfer::class, $transfers[0]);
62
63
                return true;
64
            }),
65
        );
66
67
        // Act
68
        $this->tester->setupMessageBroker(InitializeProductExportTransfer::class, $channelName);
69
        $this->tester->setupMessageBrokerPlugins();
70
        $messageBrokerFacade = $this->tester->getLocator()->messageBroker()->facade();
71
        $messageBrokerFacade->sendMessage(
72
            $this->tester->buildInitializeProductExportTransfer(),
73
        );
74
        $messageBrokerFacade->startWorker(
75
            $this->tester->buildMessageBrokerWorkerConfigTransfer([$channelName], 1),
76
        );
77
    }
78
}
79