Passed
Pull Request — master (#365)
by Dmitry
21:01
created

handleSearchMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 10
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 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
namespace PyzTest\Zed\MessageBroker;
9
10
use Codeception\Actor;
11
use Generated\Shared\DataBuilder\SearchEndpointAvailableBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBui...ndpointAvailableBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\DataBuilder\SearchEndpointRemovedBuilder;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\DataBui...hEndpointRemovedBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Generated\Shared\Transfer\SearchEndpointAvailableTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...dpointAvailableTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Generated\Shared\Transfer\SearchEndpointRemovedTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...EndpointRemovedTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Generated\Shared\Transfer\StoreTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Orm\Zed\SearchHttp\Persistence\SpySearchHttpConfig;
17
use Orm\Zed\SearchHttp\Persistence\SpySearchHttpConfigQuery;
18
use Spryker\Shared\Kernel\Transfer\TransferInterface;
19
20
/**
21
 * Inherited Methods
22
 *
23
 * @method void wantToTest($text)
24
 * @method void wantTo($text)
25
 * @method void execute($callable)
26
 * @method void expectTo($prediction)
27
 * @method void expect($prediction)
28
 * @method void amGoingTo($argumentation)
29
 * @method void am($role)
30
 * @method void lookForwardTo($achieveValue)
31
 * @method void comment($description)
32
 * @method void pause()
33
 *
34
 * @SuppressWarnings(\PyzTest\Zed\SearchHttp\PHPMD)
35
 */
36
class SearchHttpCommunicationTester extends Actor
37
{
38
    use _generated\SearchHttpCommunicationTesterActions;
0 ignored issues
show
Bug introduced by
The type PyzTest\Zed\MessageBroke...municationTesterActions was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
40
    /**
41
     * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer
42
     *
43
     * @return void
44
     */
45
    public function assertSearchHttpConfigExistsForStore(StoreTransfer $storeTransfer): void
46
    {
47
        $searchHttpConfigEntity = $this->getSearchHttpConfigEntity($storeTransfer);
48
49
        $this->assertNotNull($searchHttpConfigEntity);
50
    }
51
52
    /**
53
     * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer
54
     *
55
     * @return void
56
     */
57
    public function assertSearchHttpConfigIsRemovedForStore(StoreTransfer $storeTransfer): void
58
    {
59
        $searchHttpConfigEntity = $this->getSearchHttpConfigEntity($storeTransfer);
60
61
        $this->assertSame(
62
            ['search_http_configs' => []],
63
            $searchHttpConfigEntity->getData(),
64
        );
65
    }
66
67
    /**
68
     * @return \Generated\Shared\Transfer\SearchEndpointAvailableTransfer
69
     */
70
    public function buildSearchEndpointAvailableTransfer(): SearchEndpointAvailableTransfer
71
    {
72
        return (new SearchEndpointAvailableBuilder())
73
            ->withMessageAttributes()
74
            ->build();
75
    }
76
77
    /**
78
     * @return \Generated\Shared\Transfer\SearchEndpointRemovedTransfer
79
     */
80
    public function buildSearchEndpointRemovedTransfer(): SearchEndpointRemovedTransfer
81
    {
82
        return (new SearchEndpointRemovedBuilder())
83
            ->withMessageAttributes()
84
            ->build();
85
    }
86
87
    /**
88
     * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer
89
     *
90
     * @return void
91
     */
92
    public function removeHttpConfigForStore(StoreTransfer $storeTransfer): void
93
    {
94
        (new SpySearchHttpConfigQuery())
95
            ->filterByStoreName($storeTransfer->getName())
96
            ->delete();
97
    }
98
99
    /**
100
     * @param \Spryker\Shared\Kernel\Transfer\TransferInterface $searchMessageTransfer
101
     *
102
     * @return void
103
     */
104
    public function handleSearchMessage(TransferInterface $searchMessageTransfer): void
105
    {
106
        $channelName = 'search-commands';
107
        $this->setupMessageBroker($searchMessageTransfer::class, $channelName);
108
        $messageBrokerFacade = $this->getLocator()->messageBroker()->facade();
109
        $messageBrokerFacade->sendMessage($searchMessageTransfer);
110
        $messageBrokerFacade->startWorker(
111
            $this->buildMessageBrokerWorkerConfigTransfer([$channelName], 1),
112
        );
113
        $this->resetInMemoryMessages();
114
    }
115
116
    /**
117
     * @param \Generated\Shared\Transfer\StoreTransfer $storeTransfer
118
     *
119
     * @return \Orm\Zed\SearchHttp\Persistence\SpySearchHttpConfig|null
120
     */
121
    protected function getSearchHttpConfigEntity(StoreTransfer $storeTransfer): ?SpySearchHttpConfig
122
    {
123
        return (new SpySearchHttpConfigQuery())
124
            ->filterByStoreName($storeTransfer->getName())
125
            ->findOne();
126
    }
127
}
128