Completed
Pull Request — master (#330)
by Stefan
04:36
created

ArticleTest::testRegenerateWhenUpdateIsManual()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Tests\ShopwarePlugins\Connect\Subscribers;
4
5
use ShopwarePlugins\Connect\Components\Config;
6
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamsAssignments;
7
use ShopwarePlugins\Connect\Subscribers\Article;
8
use Shopware\Connect\Gateway;
9
use Shopware\Components\Model\ModelManager;
10
use ShopwarePlugins\Connect\Components\ConnectExport;
11
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamService;
12
use Tests\ShopwarePlugins\Connect\ConnectTestHelper;
13
use Shopware\Models\Article\Article as ArticleModel;
14
use Doctrine\ORM\EntityRepository;
15
use ShopwarePlugins\Connect\Components\Helper;
16
use Shopware\CustomModels\Connect\Attribute as ConnectAttribute;
17
use Doctrine\DBAL\Connection;
18
19
class ArticleTest extends ConnectTestHelper
20
{
21
    /**
22
     * @var Article
23
     */
24
    private $subscriber;
25
26
    /**
27
     * @var ModelManager
28
     */
29
    private $modelManager;
30
31
    /**
32
     * @var Helper
33
     */
34
    private $helper;
35
36
    /**
37
     * @var ConnectExport
38
     */
39
    private $connectExport;
40
41
    /**
42
     * @var Config
43
     */
44
    private $config;
45
46
    public function setUp()
47
    {
48
        $this->modelManager = $this->createMock(ModelManager::class);
49
        $this->helper = $this->createMock(Helper::class);
50
        $this->connectExport = $this->createMock(ConnectExport::class);
51
        $this->config = $this->createMock(Config::class);
52
53
        $this->subscriber = new Article(
54
            $this->createMock(Gateway::class),
55
            $this->modelManager,
56
            $this->connectExport,
57
            $this->createMock(ProductStreamService::class),
58
            $this->helper,
59
            $this->config
60
        );
61
    }
62
63
    public function testRegenerateChanges()
64
    {
65
        $articleId = 5;
66
        $article = new ArticleModel();
67
        $connectAttribute = new ConnectAttribute();
68
69
        $repositoryMock = $this->createMock(EntityRepository::class);
70
71
        $this->modelManager->method('getRepository')
72
            ->with(ArticleModel::class)
73
            ->willReturn($repositoryMock);
74
75
        $repositoryMock->method('find')
76
            ->with($articleId)
77
            ->willReturn($article);
78
79
        $this->helper->method('getConnectAttributeByModel')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Helper>.

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...
80
            ->with($article)
81
            ->willReturn($connectAttribute);
82
83
        $this->helper->method('isProductExported')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Helper>.

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...
84
            ->with($connectAttribute)
85
            ->willReturn(true);
86
87
        $this->connectExport->method('setDeleteStatusForVariants')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
88
            ->with($article);
89
90
        $this->config->method('getConfig')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Config>.

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...
91
            ->with('autoUpdateProducts', Config::UPDATE_AUTO)
92
            ->willReturn(Config::UPDATE_AUTO);
93
94
        $sourceIds = ['5', '5-101', '5-102', '5-103'];
95
        $this->helper->method('getSourceIdsFromArticleId')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Helper>.

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...
96
            ->with($articleId)
97
            ->willReturn($sourceIds);
98
99
        $this->connectExport->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
100
            ->method('export')
101
            ->with($sourceIds, new ProductStreamsAssignments());
102
103
        $this->subscriber->regenerateChangesForArticle($articleId);
104
    }
105
106
    public function testRegenerateSkipsNotExportedProduct()
107
    {
108
        $articleId = 5;
109
        $article = new ArticleModel();
110
        $connectAttribute = new ConnectAttribute();
111
112
        $repositoryMock = $this->createMock(EntityRepository::class);
113
114
        $this->modelManager->method('getRepository')
115
            ->with(ArticleModel::class)
116
            ->willReturn($repositoryMock);
117
118
        $repositoryMock->method('find')
119
            ->with($articleId)
120
            ->willReturn($article);
121
122
        $this->helper->method('getConnectAttributeByModel')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Helper>.

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...
123
            ->with($article)
124
            ->willReturn($connectAttribute);
125
126
        $this->helper->method('isProductExported')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Helper>.

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...
127
            ->with($connectAttribute)
128
            ->willReturn(false);
129
130
        $this->connectExport->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
131
            ->method('export');
132
133
        $this->subscriber->regenerateChangesForArticle($articleId);
134
    }
135
136
    public function testRegenerateSkipsMissingArticles()
137
    {
138
        $repositoryMock = $this->createMock(EntityRepository::class);
139
140
        $this->modelManager->method('getRepository')
141
            ->with(ArticleModel::class)
142
            ->willReturn($repositoryMock);
143
144
        $this->connectExport->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
145
            ->method('export');
146
147
        $this->subscriber->regenerateChangesForArticle(5);
148
    }
149
150
151
152
    public function testRegenerateSkipsWhenConnectAttributeIsMissing()
153
    {
154
        $articleId = 5;
155
        $article = new ArticleModel();
156
157
        $repositoryMock = $this->createMock(EntityRepository::class);
158
159
        $this->modelManager->method('getRepository')
160
            ->with(ArticleModel::class)
161
            ->willReturn($repositoryMock);
162
163
        $repositoryMock->method('find')
164
            ->with($articleId)
165
            ->willReturn($article);
166
167
        $this->connectExport->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
168
            ->method('export');
169
170
        $this->subscriber->regenerateChangesForArticle($articleId);
171
    }
172
173
    public function testRegenerateWhenCronIsEnabled()
174
    {
175
        $articleId = 5;
176
        $article = new ArticleModel();
177
        $connectAttribute = new ConnectAttribute();
178
179
        $repositoryMock = $this->createMock(EntityRepository::class);
180
181
        $this->modelManager->method('getRepository')
182
            ->with(ArticleModel::class)
183
            ->willReturn($repositoryMock);
184
185
        $repositoryMock->method('find')
186
            ->with($articleId)
187
            ->willReturn($article);
188
189
        $this->helper->method('getConnectAttributeByModel')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Helper>.

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...
190
            ->with($article)
191
            ->willReturn($connectAttribute);
192
193
        $this->helper->method('isProductExported')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Helper>.

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...
194
            ->with($connectAttribute)
195
            ->willReturn(true);
196
197
        $this->connectExport->method('setDeleteStatusForVariants')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
198
            ->with($article);
199
200
        $this->config->method('getConfig')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Config>.

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...
201
            ->with('autoUpdateProducts', Config::UPDATE_AUTO)
202
            ->willReturn(Config::UPDATE_CRON_JOB);
203
204
        $connectionMock = $this->createMock(Connection::class);
205
        $this->modelManager->method('getConnection')
206
            ->willReturn($connectionMock);
207
        $connectionMock->expects($this->once())
208
            ->method('update')
209
            ->with(
210
                's_plugin_connect_items',
211
                ['cron_update' => 1],
212
                ['article_id' => $articleId]
213
            );
214
215
        $this->connectExport->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
216
            ->method('export');
217
218
        $this->subscriber->regenerateChangesForArticle($articleId);
219
    }
220
221
    public function testRegenerateWhenUpdateIsManual()
222
    {
223
        $this->config->method('getConfig')
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<ShopwarePlugins\Connect\Components\Config>.

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...
224
            ->with('autoUpdateProducts', Config::UPDATE_AUTO)
225
            ->willReturn(Config::UPDATE_MANUAL);
226
227
        $this->modelManager->expects($this->never())
228
            ->method('getRepository');
229
        $this->connectExport->expects($this->never())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<ShopwarePlugins\C...mponents\ConnectExport>.

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...
230
            ->method('export');
231
232
        $this->subscriber->regenerateChangesForArticle(5);
233
    }
234
}
235