Completed
Push — pac-252--category-product-rewr... ( cfd311...95ead2 )
by Marcus
02:14
created

UrlRewriteObserverTest::createAndInvokeObserver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\UrlRewrite\Observers\UrlRewriteObserverTest
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-product-url-rewrite
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\UrlRewrite\Observers;
22
23
use PHPUnit\Framework\TestCase;
24
use ReflectionClass;
25
use TechDivision\Import\Utils\EntityStatus;
26
use TechDivision\Import\Utils\StoreViewCodes;
27
use TechDivision\Import\Product\Utils\VisibilityKeys;
28
use TechDivision\Import\Product\Utils\CoreConfigDataKeys;
29
use TechDivision\Import\Product\UrlRewrite\Utils\ColumnKeys;
30
use TechDivision\Import\Product\UrlRewrite\Utils\MemberNames;
31
use TechDivision\Import\Adapter\SerializerAwareAdapterInterface;
32
33
/**
34
 * Test class for the product URL rewrite observer implementation.
35
 *
36
 * @author    Tim Wagner <[email protected]>
37
 * @copyright 2016 TechDivision GmbH <[email protected]>
38
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
39
 * @link      https://github.com/techdivision/import-product-url-rewrite
40
 * @link      http://www.techdivision.com
41
 */
42
class UrlRewriteObserverTest extends TestCase
43
{
44
45
    /**
46
     * The observer we want to test.
47
     *
48
     * @var \TechDivision\Import\Product\UrlRewrite\Observers\UrlRewriteObserver
49
     */
50
    protected $observer;
51
52
    /**
53
     * A mock processor instance.
54
     *
55
     * @var \TechDivision\Import\Product\UrlRewrite\Services\ProductUrlRewriteProcessorInterface
56
     */
57
    protected $mockProductUrlRewriteProcessor;
58
59
    /**
60
     * Sets up the fixture, for example, open a network connection.
61
     * This method is called before a test is executed.
62
     *
63
     * @return void
64
     * @see \PHPUnit\Framework\TestCase::setUp()
65
     */
66 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
    {
68
69
        // initialize a mock processor instance
70
        $this->mockProductUrlRewriteProcessor = $this->getMockBuilder('TechDivision\Import\Product\UrlRewrite\Services\ProductUrlRewriteProcessorInterface')
71
                                                     ->setMethods(get_class_methods('TechDivision\Import\Product\UrlRewrite\Services\ProductUrlRewriteProcessorInterface'))
72
                                                     ->getMock();
73
74
        // initialize the observer
75
        $this->observer = new UrlRewriteObserver($this->mockProductUrlRewriteProcessor);
76
    }
77
78
    protected function createAndInvokeObserver($generateCategoryProductRewrites = true, $productCategoryIds = [], $category = [])
79
    {
80
        $observer = $this->getMockBuilder('TechDivision\Import\Product\UrlRewrite\Observers\UrlRewriteObserver')
81
            ->setConstructorArgs([$this->mockProductUrlRewriteProcessor])
82
            ->setMethods(['getGenerateCategoryProductRewritesOptionValue'])
83
            ->getMock();
84
85
        $observer->expects($this->any())
86
            ->method('getGenerateCategoryProductRewritesOptionValue')
87
            ->willReturn($generateCategoryProductRewrites);
88
89
        // prepare protected properties of observer
90
        $reflection = new ReflectionClass('TechDivision\Import\Product\UrlRewrite\Observers\UrlRewriteObserver');
91
        $property = $reflection->getProperty('productCategoryIds');
92
        $property->setAccessible(true);
93
        $property->setValue($observer, $productCategoryIds);
94
95
        // invoke the method to test
96
        $method = $reflection->getMethod('createProductCategoryRelation');
97
        $method->setAccessible(true);
98
        $method->invoke($observer, $category, true);
99
100
        return $property->getValue($observer);
101
    }
102
103
    public function testCreateProductCategoryRelationWithChildCategoryAndSettingEnabled()
104
    {
105
106
        // initialize method arguments
107
        $generateCategoryProductRewrites = true;
108
        $productCategoryIds = ['2'];
109
        $category = [
110
            'entity_id' => '10',
111
            'is_anchor' => '0'
112
        ];
113
114
        // create and invoke the partially mocked observer
115
        $productCategoryIds = $this->createAndInvokeObserver($generateCategoryProductRewrites, $productCategoryIds, $category);
116
117
        $this->assertSame($productCategoryIds, ['2', '10']);
118
    }
119
120
    /**
121
     * Test's the handle() method with a successful URL rewrite persist.
122
     *
123
     * @return void
124
     */
125
    public function testHandleWithSuccessfullCreateWithoutCategories()
126
    {
127
128
        // create a dummy CSV file header
129
        $headers = array(
130
            'sku'             => 0,
131
            'url_key'         => 1,
132
            'store_view_code' => 2,
133
            'visibility'      => 3,
134
            'categories'      => 4
135
        );
136
137
        // create a dummy CSV file row
138
        $row = array(
139
            0 => $sku = 'TEST-01',
140
            1 => 'bruno-compete-hoodie-test',
141
            2 => $storeViewCode = 'default',
142
            3 => 'Catalog, Search',
143
            4 => null
144
        );
145
146
        // initialize category and entity ID
147
        $categoryId = 2;
148
        $entityId = 61413;
149
150
        // create a mock subject
151
        $mockSubject = $this->getMockBuilder('TechDivision\Import\Product\UrlRewrite\Subjects\UrlRewriteSubject')
152
                            ->setMethods(
153
                                array(
154
                                    'hasHeader',
155
                                    'getHeader',
156
                                    'getHeaders',
157
                                    'getRootCategory',
158
                                    'getCategory',
159
                                    'getCoreConfigData',
160
                                    'getRowStoreId',
161
                                    'getRow',
162
                                    'hasBeenProcessed',
163
                                    'addEntityIdVisibilityIdMapping',
164
                                    'getEntityIdVisibilityIdMapping',
165
                                    'getStoreViewCode',
166
                                    'isDebugMode',
167
                                    'storeIsActive'
168
                                )
169
                            )
170
                            ->disableOriginalConstructor()
171
                            ->getMock();
172
173
        // mock the methods
174
        $mockSubject->expects($this->any())
175
                    ->method('isDebugMode')
176
                    ->willReturn(false);
177
        $mockSubject->expects($this->any())
178
                    ->method('getHeaders')
179
                    ->willReturn($headers);
180
        $mockSubject->expects($this->any())
181
                    ->method('getRow')
182
                    ->willReturn($row);
183
        $mockSubject->expects($this->any())
184
                    ->method('hasHeader')
185
                    ->willReturn(true);
186
        $mockSubject->expects($this->any())
187
                    ->method('getHeader')
188
                    ->withConsecutive(
189
                        array(ColumnKeys::SKU),
190
                        array(ColumnKeys::URL_KEY),
191
                        array(ColumnKeys::URL_KEY),
192
                        array(ColumnKeys::STORE_VIEW_CODE),
193
                        array(ColumnKeys::VISIBILITY),
194
                        array(ColumnKeys::STORE_VIEW_CODE),
195
                        array(ColumnKeys::CATEGORIES),
196
                        array(ColumnKeys::STORE_VIEW_CODE)
197
                    )
198
                    ->willReturnOnConsecutiveCalls(0, 1, 1, 2, 3, 2, 4, 2);
199
        $mockSubject->expects($this->once())
200
                    ->method('hasBeenProcessed')
201
                    ->willReturn(false);
202
        $mockSubject->expects($this->once())
203
                    ->method('getEntityIdVisibilityIdMapping')
204
                    ->willReturn(VisibilityKeys::VISIBILITY_BOTH);
205
        $mockSubject->expects($this->exactly(1))
206
                    ->method('getRowStoreId')
207
                    ->willReturn($storeId = 1);
208
        $mockSubject->expects($this->exactly(2))
209
                    ->method('getCategory')
210
                    ->with($categoryId)
211
                    ->willReturn($category = array(MemberNames::ENTITY_ID => $categoryId, MemberNames::PARENT_ID => 1, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => null));
212
        $mockSubject->expects($this->exactly(5))
213
                    ->method('getRootCategory')
214
                    ->willReturn($category);
215
        $mockSubject->expects($this->once())
216
                    ->method('getStoreViewCode')
217
                    ->with(StoreViewCodes::ADMIN)
218
                    ->willReturn($storeViewCode);
219
        $mockSubject->expects($this->once())
220
                    ->method('storeIsActive')
221
                    ->with($storeViewCode)
222
                    ->willReturn(true);
223
        $mockSubject->expects($this->exactly(1))
224
                    ->method('getCoreConfigData')
225
                    ->with(CoreConfigDataKeys::CATALOG_SEO_PRODUCT_URL_SUFFIX, '.html')
226
                    ->willReturn('.html');
227
228
        // mock the processor methods
229
        $this->mockProductUrlRewriteProcessor->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<TechDivision\Impo...riteProcessorInterface>.

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('loadProduct')
231
                    ->with($sku)
232
                    ->willReturn(array(MemberNames::ENTITY_ID => $entityId));
233
        $this->mockProductUrlRewriteProcessor->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<TechDivision\Impo...riteProcessorInterface>.

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...
234
                    ->method('persistUrlRewrite')
235
                    ->with(
236
                        array(
237
                            MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
238
                            MemberNames::ENTITY_ID        => $entityId,
239
                            MemberNames::REQUEST_PATH     => sprintf('%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
240
                            MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s', $entityId),
241
                            MemberNames::REDIRECT_TYPE    => 0,
242
                            MemberNames::STORE_ID         => $storeId,
243
                            MemberNames::DESCRIPTION      => null,
244
                            MemberNames::IS_AUTOGENERATED => 1,
245
                            MemberNames::METADATA         => null,
246
                            EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
247
                        )
248
                    )
249
                    ->willReturn(1000);
250
251
        // invoke the handle() method
252
        $this->assertSame($row, $this->observer->handle($mockSubject));
253
    }
254
255
    /**
256
     * Test's the handle() method with a successful URL rewrite persist when using the same categories.
257
     *
258
     * @return void
259
     */
260
    public function testHandleWithSuccessfullUpdateAndSameCategories()
261
    {
262
263
        // initialize the entity ID to use
264
        $entityId = 61413;
265
266
        // create a dummy CSV file row
267
        $headers = array(
268
            'sku'                => 0,
269
            'url_key'            => 1,
270
            'categories'         => 2,
271
            'store_view_code'    => 3,
272
            'visibility'         => 4
273
        );
274
275
        // create a dummy CSV file header
276
        $row = array(
277
            0 => $sku = 'TEST-01',
278
            1 => 'bruno-compete-hoodie',
279
            2 => 'Default Category/Men/Tops/Hoodies & Sweatshirts,Default Category/Collections/Eco Friendly,Default Category',
280
            3 => $storeViewCode = 'default',
281
            4 => 'Catalog, Search'
282
        );
283
284
        // initialize the categories
285
        $categories = array(
286
             $path1 = 'Default Category'                                => array(MemberNames::ENTITY_ID => 2, MemberNames::PARENT_ID => 1, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => null, MemberNames::PATH => $path1),
287
             $path2 = 'Default Category/Men'                            => array(MemberNames::ENTITY_ID => 3, MemberNames::PARENT_ID => 2, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => 'men', MemberNames::PATH => $path2),
288
             $path3 = 'Default Category/Men/Tops'                       => array(MemberNames::ENTITY_ID => 4, MemberNames::PARENT_ID => 3, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => 'men/tops-men', MemberNames::PATH => $path3),
289
             $path4 = 'Default Category/Men/Tops/Hoodies & Sweatshirts' => array(MemberNames::ENTITY_ID => 5, MemberNames::PARENT_ID => 4, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => 'men/tops-men/hoodies-and-sweatshirts-men', MemberNames::PATH => $path4),
290
             $path5 = 'Default Category/Collections'                    => array(MemberNames::ENTITY_ID => 6, MemberNames::PARENT_ID => 3, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => 'collections', MemberNames::PATH => $path5),
291
             $path6 = 'Default Category/Collections/Eco Friendly'       => array(MemberNames::ENTITY_ID => 7, MemberNames::PARENT_ID => 6, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => 'collections/eco-friendly', MemberNames::PATH => $path6),
292
        );
293
294
        // initialize a mock import adapter instance
295
        $mockImportAdapter = $this->getMockBuilder(SerializerAwareAdapterInterface::class)->getMock();
296
        $mockImportAdapter->expects($this->exactly(4))
297
            ->method('explode')
298
            ->withConsecutive(
299
                array($row[2]),
300
                array('Default Category/Men/Tops/Hoodies & Sweatshirts'),
301
                array('Default Category/Collections/Eco Friendly'),
302
                array('Default Category')
303
            )
304
            ->willReturnOnConsecutiveCalls(
305
                array('Default Category/Men/Tops/Hoodies & Sweatshirts', 'Default Category/Collections/Eco Friendly', 'Default Category'),
306
                array('Default Category', 'Men', 'Tops', 'Hoodies & Sweatshirts'),
307
                array('Default Category', 'Collections', 'Eco Friendly'),
308
                array('Default Category')
309
            );
310
311
        // mock the system logger
312
        $mockSystemLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')
313
                                 ->setMethods(get_class_methods('Psr\Log\LoggerInterface'))
314
                                 ->getMock();
315
316
        // create a mock subject
317
        $mockSubject = $this->getMockBuilder('TechDivision\Import\Product\UrlRewrite\Subjects\UrlRewriteSubject')
318
                            ->setMethods(
319
                                array(
320
                                    'hasHeader',
321
                                    'getHeader',
322
                                    'getHeaders',
323
                                    'getRootCategory',
324
                                    'getRowStoreId',
325
                                    'getCategory',
326
                                    'getCoreConfigData',
327
                                    'getRow',
328
                                    'hasBeenProcessed',
329
                                    'addEntityIdVisibilityIdMapping',
330
                                    'getEntityIdVisibilityIdMapping',
331
                                    'getStoreViewCode',
332
                                    'isDebugMode',
333
                                    'storeIsActive',
334
                                    'getCategoryByPath',
335
                                    'getSystemLogger',
336
                                    'getImportAdapter'
337
                                )
338
                            )
339
                            ->disableOriginalConstructor()
340
                            ->getMock();
341
342
        // mock the methods
343
        $mockSubject->expects($this->any())
344
                    ->method('getSystemLogger')
345
                    ->willReturn($mockSystemLogger);
346
        $mockSubject->expects($this->any())
347
                    ->method('isDebugMode')
348
                    ->willReturn(false);
349
        $mockSubject->expects($this->any())
350
                    ->method('getHeaders')
351
                    ->willReturn($headers);
352
        $mockSubject->expects($this->any())
353
                    ->method('getRow')
354
                    ->willReturn($row);
355
        $mockSubject->expects($this->any())
356
                    ->method('hasHeader')
357
                    ->willReturn(true);
358
        $mockSubject->expects($this->any())
359
                    ->method('getSystemLogger')
360
                    ->willReturn($mockSystemLogger);
361
        $mockSubject->expects($this->any())
362
                    ->method('getHeader')
363
                    ->withConsecutive(
364
                        array(ColumnKeys::SKU),
365
                        array(ColumnKeys::URL_KEY),
366
                        array(ColumnKeys::URL_KEY),
367
                        array(ColumnKeys::STORE_VIEW_CODE),
368
                        array(ColumnKeys::VISIBILITY),
369
                        array(ColumnKeys::STORE_VIEW_CODE),
370
                        array(ColumnKeys::CATEGORIES),
371
                        array(ColumnKeys::STORE_VIEW_CODE)
372
                    )
373
                    ->willReturnOnConsecutiveCalls(0, 1, 1, 3, 4, 3, 2, 3);
374
        $mockSubject->expects($this->once())
375
                    ->method('hasBeenProcessed')
376
                    ->willReturn(false);
377
        $mockSubject->expects($this->exactly(3))
378
                    ->method('getCategoryByPath')
379
                    ->withConsecutive(
380
                        array($path4 /* Default Category/Men/Tops/Hoodies & Sweatshirts */),
381
                        array($path6 /* Default Category/Collections/Eco Friendly */),
382
                        array($path1 /* Default Category */)
383
                    )
384
                    ->willReturnOnConsecutiveCalls(
385
                        $categories[$path4],
386
                        $categories[$path6],
387
                        $categories[$path1]
388
                    );
389
        $mockSubject->expects($this->exactly(13))
390
                    ->method('getCategory')
391
                    ->withConsecutive(
392
                        array($categories[$path4][MemberNames::ENTITY_ID]),
393
                        array($categories[$path3][MemberNames::ENTITY_ID]),
394
                        array($categories[$path2][MemberNames::ENTITY_ID]),
395
                        array($categories[$path6][MemberNames::ENTITY_ID]),
396
                        array($categories[$path5][MemberNames::ENTITY_ID]),
397
                        array($categories[$path2][MemberNames::ENTITY_ID]),
398
                        array($categories[$path1][MemberNames::ENTITY_ID]),
399
                        array($categories[$path1][MemberNames::ENTITY_ID]),
400
                        array($categories[$path4][MemberNames::ENTITY_ID]),
401
                        array($categories[$path6][MemberNames::ENTITY_ID]),
402
                        array($categories[$path1][MemberNames::ENTITY_ID]),
403
                        array($categories[$path4][MemberNames::ENTITY_ID]),
404
                        array($categories[$path6][MemberNames::ENTITY_ID])
405
                    )
406
                    ->willReturnOnConsecutiveCalls(
407
                        $categories[$path4],
408
                        $categories[$path3],
409
                        $categories[$path2],
410
                        $categories[$path6],
411
                        $categories[$path5],
412
                        $categories[$path2],
413
                        $categories[$path1],
414
                        $categories[$path1],
415
                        $categories[$path4],
416
                        $categories[$path6],
417
                        $categories[$path1],
418
                        $categories[$path4],
419
                        $categories[$path6]
420
                    );
421
        $mockSubject->expects($this->any())
422
                    ->method('getRootCategory')
423
                    ->willReturn($categories[$path1]);
424
        $mockSubject->expects($this->once())
425
                    ->method('getStoreViewCode')
426
                    ->with(StoreViewCodes::ADMIN)
427
                    ->willReturn($storeViewCode);
428
        $mockSubject->expects($this->once())
429
                    ->method('storeIsActive')
430
                    ->with($storeViewCode)
431
                    ->willReturn(true);
432
        $mockSubject->expects($this->once())
433
                    ->method('getEntityIdVisibilityIdMapping')
434
                    ->willReturn(VisibilityKeys::VISIBILITY_BOTH);
435
        $mockSubject->expects($this->any())
436
                    ->method('getRowStoreId')
437
                    ->willReturn($storeId = 1);
438
        $mockSubject->expects($this->exactly(3))
439
                    ->method('getCoreConfigData')
440
                    ->withConsecutive(
441
                        array(CoreConfigDataKeys::CATALOG_SEO_PRODUCT_URL_SUFFIX, '.html'),
442
                        array(CoreConfigDataKeys::CATALOG_SEO_PRODUCT_URL_SUFFIX, '.html'),
443
                        array(CoreConfigDataKeys::CATALOG_SEO_PRODUCT_URL_SUFFIX, '.html')
444
                    )
445
                    ->willReturnOnConsecutiveCalls('.html', '.html', '.html');
446
       $mockSubject->expects(($this->exactly(4)))
447
                    ->method('getImportAdapter')
448
                    ->willReturn($mockImportAdapter);
449
450
        // mock the processor methods
451
        $this->mockProductUrlRewriteProcessor->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<TechDivision\Impo...riteProcessorInterface>.

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...
452
                    ->method('loadProduct')
453
                    ->with($sku)
454
                    ->willReturn(array(MemberNames::ENTITY_ID => $entityId));
455
        $this->mockProductUrlRewriteProcessor->expects($this->exactly(3))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<TechDivision\Impo...riteProcessorInterface>.

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...
456
                    ->method('persistUrlRewrite')
457
                    ->withConsecutive(
458
                        array(
459
                            array(
460
                                MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
461
                                MemberNames::ENTITY_ID        => $entityId,
462
                                MemberNames::REQUEST_PATH     => sprintf('%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
463
                                MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s', $entityId),
464
                                MemberNames::REDIRECT_TYPE    => 0,
465
                                MemberNames::STORE_ID         => $storeId,
466
                                MemberNames::DESCRIPTION      => null,
467
                                MemberNames::IS_AUTOGENERATED => 1,
468
                                MemberNames::METADATA         => null,
469
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
470
                            )
471
                        ),
472
                        array(
473
                            array(
474
                                MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
475
                                MemberNames::ENTITY_ID        => $entityId,
476
                                MemberNames::REQUEST_PATH     => sprintf('men/tops-men/hoodies-and-sweatshirts-men/%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
477
                                MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s/category/5', $entityId),
478
                                MemberNames::REDIRECT_TYPE    => 0,
479
                                MemberNames::STORE_ID         => $storeId,
480
                                MemberNames::DESCRIPTION      => null,
481
                                MemberNames::IS_AUTOGENERATED => 1,
482
                                MemberNames::METADATA         => json_encode(array('category_id' => "5")),
483
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
484
                            )
485
                        ),
486
                        array(
487
                            array(
488
                                MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
489
                                MemberNames::ENTITY_ID        => $entityId,
490
                                MemberNames::REQUEST_PATH     => sprintf('collections/eco-friendly/%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
491
                                MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s/category/7', $entityId),
492
                                MemberNames::REDIRECT_TYPE    => 0,
493
                                MemberNames::STORE_ID         => $storeId,
494
                                MemberNames::DESCRIPTION      => null,
495
                                MemberNames::IS_AUTOGENERATED => 1,
496
                                MemberNames::METADATA         => json_encode(array('category_id' => "7")),
497
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
498
                            )
499
                        )
500
                    )
501
                    ->willReturnOnConsecutiveCalls(1000, 1001, 1002);
502
        $this->mockProductUrlRewriteProcessor->expects($this->exactly(2))
0 ignored issues
show
Bug introduced by
The method expects() does not seem to exist on object<TechDivision\Impo...riteProcessorInterface>.

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...
503
                    ->method('persistUrlRewriteProductCategory')
504
                    ->withConsecutive(
505
                        array(
506
                            array(
507
                                MemberNames::URL_REWRITE_ID   => 1001,
508
                                MemberNames::PRODUCT_ID       => $entityId,
509
                                MemberNames::CATEGORY_ID      => 5,
510
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
511
                            )
512
                        ),
513
                        array(
514
                            array(
515
                                MemberNames::URL_REWRITE_ID   => 1002,
516
                                MemberNames::PRODUCT_ID       => $entityId,
517
                                MemberNames::CATEGORY_ID      => 7,
518
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
519
                            )
520
                        )
521
                    );
522
523
        // invoke the handle() method
524
        $this->assertSame($row, $this->observer->handle($mockSubject));
0 ignored issues
show
Documentation introduced by
$mockSubject is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<TechDivision\Impo...jects\SubjectInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
525
    }
526
}
527