Completed
Push — master ( c10821...87327d )
by Tim
16s queued 11s
created

testCreateProductCategoryRelationWithChildCategoryAndSettingEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 0
Metric Value
dl 16
loc 16
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
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', 'isRootCategory'])
83
            ->getMock();
84
85
        $observer->expects($this->any())
86
            ->method('getGenerateCategoryProductRewritesOptionValue')
87
            ->willReturn($generateCategoryProductRewrites);
88
89
        $observer->expects($this->any())
90
            ->method('isRootCategory')
91
            ->willReturn(false);
92
93
        // prepare protected properties of observer
94
        $reflection = new ReflectionClass('TechDivision\Import\Product\UrlRewrite\Observers\UrlRewriteObserver');
95
        $property = $reflection->getProperty('productCategoryIds');
96
        $property->setAccessible(true);
97
        $property->setValue($observer, $productCategoryIds);
98
99
        // invoke the method to test
100
        $method = $reflection->getMethod('createProductCategoryRelation');
101
        $method->setAccessible(true);
102
        $method->invoke($observer, $category, true);
103
104
        return $property->getValue($observer);
105
    }
106
107 View Code Duplication
    public function testCreateProductCategoryRelationWithChildCategoryAndSettingEnabled()
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...
108
    {
109
110
        // initialize method arguments
111
        $generateCategoryProductRewrites = true;
112
        $productCategoryIds = ['2'];
113
        $category = [
114
            'entity_id' => '10',
115
            'is_anchor' => '0'
116
        ];
117
118
        // create and invoke the partially mocked observer
119
        $productCategoryIds = $this->createAndInvokeObserver($generateCategoryProductRewrites, $productCategoryIds, $category);
120
121
        $this->assertSame($productCategoryIds, ['2', '10']);
122
    }
123
124 View Code Duplication
    public function testCreateProductCategoryRelationWithChildCategoryAndSettingDisabled()
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...
125
    {
126
127
        // initialize method arguments
128
        $generateCategoryProductRewrites = false;
129
        $productCategoryIds = ['2'];
130
        $category = [
131
            'entity_id' => '10',
132
            'is_anchor' => '0'
133
        ];
134
135
        // create and invoke the partially mocked observer
136
        $productCategoryIds = $this->createAndInvokeObserver($generateCategoryProductRewrites, $productCategoryIds, $category);
137
138
        $this->assertSame($productCategoryIds, ['2']);
139
    }
140
141
    /**
142
     * Test's the handle() method with a successful URL rewrite persist.
143
     *
144
     * @return void
145
     */
146
    public function testHandleWithSuccessfullCreateWithoutCategories()
147
    {
148
149
        // create a dummy CSV file header
150
        $headers = array(
151
            'sku'             => 0,
152
            'url_key'         => 1,
153
            'store_view_code' => 2,
154
            'visibility'      => 3,
155
            'categories'      => 4
156
        );
157
158
        // create a dummy CSV file row
159
        $row = array(
160
            0 => $sku = 'TEST-01',
161
            1 => 'bruno-compete-hoodie-test',
162
            2 => $storeViewCode = 'default',
163
            3 => 'Catalog, Search',
164
            4 => null
165
        );
166
167
        // initialize category and entity ID
168
        $categoryId = 2;
169
        $entityId = 61413;
170
171
        // create a mock subject
172
        $mockSubject = $this->getMockBuilder('TechDivision\Import\Product\UrlRewrite\Subjects\UrlRewriteSubject')
173
                            ->setMethods(
174
                                array(
175
                                    'hasHeader',
176
                                    'getHeader',
177
                                    'getHeaders',
178
                                    'getRootCategory',
179
                                    'getCategory',
180
                                    'getCoreConfigData',
181
                                    'getRowStoreId',
182
                                    'getRow',
183
                                    'hasBeenProcessed',
184
                                    'addEntityIdVisibilityIdMapping',
185
                                    'getEntityIdVisibilityIdMapping',
186
                                    'getStoreViewCode',
187
                                    'isDebugMode',
188
                                    'storeIsActive'
189
                                )
190
                            )
191
                            ->disableOriginalConstructor()
192
                            ->getMock();
193
194
        // mock the methods
195
        $mockSubject->expects($this->any())
196
                    ->method('isDebugMode')
197
                    ->willReturn(false);
198
        $mockSubject->expects($this->any())
199
                    ->method('getHeaders')
200
                    ->willReturn($headers);
201
        $mockSubject->expects($this->any())
202
                    ->method('getRow')
203
                    ->willReturn($row);
204
        $mockSubject->expects($this->any())
205
                    ->method('hasHeader')
206
                    ->willReturn(true);
207
        $mockSubject->expects($this->any())
208
                    ->method('getHeader')
209
                    ->withConsecutive(
210
                        array(ColumnKeys::SKU),
211
                        array(ColumnKeys::URL_KEY),
212
                        array(ColumnKeys::URL_KEY),
213
                        array(ColumnKeys::STORE_VIEW_CODE),
214
                        array(ColumnKeys::VISIBILITY),
215
                        array(ColumnKeys::STORE_VIEW_CODE),
216
                        array(ColumnKeys::CATEGORIES),
217
                        array(ColumnKeys::STORE_VIEW_CODE)
218
                    )
219
                    ->willReturnOnConsecutiveCalls(0, 1, 1, 2, 3, 2, 4, 2);
220
        $mockSubject->expects($this->once())
221
                    ->method('hasBeenProcessed')
222
                    ->willReturn(false);
223
        $mockSubject->expects($this->once())
224
                    ->method('getEntityIdVisibilityIdMapping')
225
                    ->willReturn(VisibilityKeys::VISIBILITY_BOTH);
226
        $mockSubject->expects($this->exactly(1))
227
                    ->method('getRowStoreId')
228
                    ->willReturn($storeId = 1);
229
        $mockSubject->expects($this->exactly(2))
230
                    ->method('getCategory')
231
                    ->with($categoryId)
232
                    ->willReturn($category = array(MemberNames::ENTITY_ID => $categoryId, MemberNames::PARENT_ID => 1, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => null));
233
        $mockSubject->expects($this->exactly(5))
234
                    ->method('getRootCategory')
235
                    ->willReturn($category);
236
        $mockSubject->expects($this->once())
237
                    ->method('getStoreViewCode')
238
                    ->with(StoreViewCodes::ADMIN)
239
                    ->willReturn($storeViewCode);
240
        $mockSubject->expects($this->once())
241
                    ->method('storeIsActive')
242
                    ->with($storeViewCode)
243
                    ->willReturn(true);
244
        $mockSubject->expects($this->exactly(1))
245
                    ->method('getCoreConfigData')
246
                    ->with(CoreConfigDataKeys::CATALOG_SEO_PRODUCT_URL_SUFFIX, '.html')
247
                    ->willReturn('.html');
248
249
        // mock the processor methods
250
        $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...
251
                    ->method('loadProduct')
252
                    ->with($sku)
253
                    ->willReturn(array(MemberNames::ENTITY_ID => $entityId));
254
        $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...
255
                    ->method('persistUrlRewrite')
256
                    ->with(
257
                        array(
258
                            MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
259
                            MemberNames::ENTITY_ID        => $entityId,
260
                            MemberNames::REQUEST_PATH     => sprintf('%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
261
                            MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s', $entityId),
262
                            MemberNames::REDIRECT_TYPE    => 0,
263
                            MemberNames::STORE_ID         => $storeId,
264
                            MemberNames::DESCRIPTION      => null,
265
                            MemberNames::IS_AUTOGENERATED => 1,
266
                            MemberNames::METADATA         => null,
267
                            EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
268
                        )
269
                    )
270
                    ->willReturn(1000);
271
272
        // invoke the handle() method
273
        $this->assertSame($row, $this->observer->handle($mockSubject));
274
    }
275
276
    /**
277
     * Test's the handle() method with a successful URL rewrite persist when using the same categories.
278
     *
279
     * @return void
280
     */
281
    public function testHandleWithSuccessfullUpdateAndSameCategories()
282
    {
283
284
        // initialize the entity ID to use
285
        $entityId = 61413;
286
287
        // create a dummy CSV file row
288
        $headers = array(
289
            'sku'                => 0,
290
            'url_key'            => 1,
291
            'categories'         => 2,
292
            'store_view_code'    => 3,
293
            'visibility'         => 4
294
        );
295
296
        // create a dummy CSV file header
297
        $row = array(
298
            0 => $sku = 'TEST-01',
299
            1 => 'bruno-compete-hoodie',
300
            2 => 'Default Category/Men/Tops/Hoodies & Sweatshirts,Default Category/Collections/Eco Friendly,Default Category',
301
            3 => $storeViewCode = 'default',
302
            4 => 'Catalog, Search'
303
        );
304
305
        // initialize the categories
306
        $categories = array(
307
             $path1 = 'Default Category'                                => array(MemberNames::ENTITY_ID => 2, MemberNames::PARENT_ID => 1, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => null, MemberNames::PATH => $path1),
308
             $path2 = 'Default Category/Men'                            => array(MemberNames::ENTITY_ID => 3, MemberNames::PARENT_ID => 2, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => 'men', MemberNames::PATH => $path2),
309
             $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),
310
             $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),
311
             $path5 = 'Default Category/Collections'                    => array(MemberNames::ENTITY_ID => 6, MemberNames::PARENT_ID => 3, MemberNames::IS_ANCHOR => null, MemberNames::URL_PATH => 'collections', MemberNames::PATH => $path5),
312
             $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),
313
        );
314
315
        // initialize a mock import adapter instance
316
        $mockImportAdapter = $this->getMockBuilder(SerializerAwareAdapterInterface::class)->getMock();
317
        $mockImportAdapter->expects($this->exactly(4))
318
            ->method('explode')
319
            ->withConsecutive(
320
                array($row[2]),
321
                array('Default Category/Men/Tops/Hoodies & Sweatshirts'),
322
                array('Default Category/Collections/Eco Friendly'),
323
                array('Default Category')
324
            )
325
            ->willReturnOnConsecutiveCalls(
326
                array('Default Category/Men/Tops/Hoodies & Sweatshirts', 'Default Category/Collections/Eco Friendly', 'Default Category'),
327
                array('Default Category', 'Men', 'Tops', 'Hoodies & Sweatshirts'),
328
                array('Default Category', 'Collections', 'Eco Friendly'),
329
                array('Default Category')
330
            );
331
332
        // mock the system logger
333
        $mockSystemLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')
334
                                 ->setMethods(get_class_methods('Psr\Log\LoggerInterface'))
335
                                 ->getMock();
336
337
        // create a mock subject
338
        $mockSubject = $this->getMockBuilder('TechDivision\Import\Product\UrlRewrite\Subjects\UrlRewriteSubject')
339
                            ->setMethods(
340
                                array(
341
                                    'hasHeader',
342
                                    'getHeader',
343
                                    'getHeaders',
344
                                    'getRootCategory',
345
                                    'getRowStoreId',
346
                                    'getCategory',
347
                                    'getCoreConfigData',
348
                                    'getRow',
349
                                    'hasBeenProcessed',
350
                                    'addEntityIdVisibilityIdMapping',
351
                                    'getEntityIdVisibilityIdMapping',
352
                                    'getStoreViewCode',
353
                                    'isDebugMode',
354
                                    'storeIsActive',
355
                                    'getCategoryByPath',
356
                                    'getSystemLogger',
357
                                    'getImportAdapter'
358
                                )
359
                            )
360
                            ->disableOriginalConstructor()
361
                            ->getMock();
362
363
        // mock the methods
364
        $mockSubject->expects($this->any())
365
                    ->method('getSystemLogger')
366
                    ->willReturn($mockSystemLogger);
367
        $mockSubject->expects($this->any())
368
                    ->method('isDebugMode')
369
                    ->willReturn(false);
370
        $mockSubject->expects($this->any())
371
                    ->method('getHeaders')
372
                    ->willReturn($headers);
373
        $mockSubject->expects($this->any())
374
                    ->method('getRow')
375
                    ->willReturn($row);
376
        $mockSubject->expects($this->any())
377
                    ->method('hasHeader')
378
                    ->willReturn(true);
379
        $mockSubject->expects($this->any())
380
                    ->method('getSystemLogger')
381
                    ->willReturn($mockSystemLogger);
382
        $mockSubject->expects($this->any())
383
                    ->method('getHeader')
384
                    ->withConsecutive(
385
                        array(ColumnKeys::SKU),
386
                        array(ColumnKeys::URL_KEY),
387
                        array(ColumnKeys::URL_KEY),
388
                        array(ColumnKeys::STORE_VIEW_CODE),
389
                        array(ColumnKeys::VISIBILITY),
390
                        array(ColumnKeys::STORE_VIEW_CODE),
391
                        array(ColumnKeys::CATEGORIES),
392
                        array(ColumnKeys::STORE_VIEW_CODE)
393
                    )
394
                    ->willReturnOnConsecutiveCalls(0, 1, 1, 3, 4, 3, 2, 3);
395
        $mockSubject->expects($this->once())
396
                    ->method('hasBeenProcessed')
397
                    ->willReturn(false);
398
        $mockSubject->expects($this->exactly(3))
399
                    ->method('getCategoryByPath')
400
                    ->withConsecutive(
401
                        array($path4 /* Default Category/Men/Tops/Hoodies & Sweatshirts */),
402
                        array($path6 /* Default Category/Collections/Eco Friendly */),
403
                        array($path1 /* Default Category */)
404
                    )
405
                    ->willReturnOnConsecutiveCalls(
406
                        $categories[$path4],
407
                        $categories[$path6],
408
                        $categories[$path1]
409
                    );
410
        $mockSubject->expects($this->exactly(13))
411
                    ->method('getCategory')
412
                    ->withConsecutive(
413
                        array($categories[$path4][MemberNames::ENTITY_ID]),
414
                        array($categories[$path3][MemberNames::ENTITY_ID]),
415
                        array($categories[$path2][MemberNames::ENTITY_ID]),
416
                        array($categories[$path6][MemberNames::ENTITY_ID]),
417
                        array($categories[$path5][MemberNames::ENTITY_ID]),
418
                        array($categories[$path2][MemberNames::ENTITY_ID]),
419
                        array($categories[$path1][MemberNames::ENTITY_ID]),
420
                        array($categories[$path1][MemberNames::ENTITY_ID]),
421
                        array($categories[$path4][MemberNames::ENTITY_ID]),
422
                        array($categories[$path6][MemberNames::ENTITY_ID]),
423
                        array($categories[$path1][MemberNames::ENTITY_ID]),
424
                        array($categories[$path4][MemberNames::ENTITY_ID]),
425
                        array($categories[$path6][MemberNames::ENTITY_ID])
426
                    )
427
                    ->willReturnOnConsecutiveCalls(
428
                        $categories[$path4],
429
                        $categories[$path3],
430
                        $categories[$path2],
431
                        $categories[$path6],
432
                        $categories[$path5],
433
                        $categories[$path2],
434
                        $categories[$path1],
435
                        $categories[$path1],
436
                        $categories[$path4],
437
                        $categories[$path6],
438
                        $categories[$path1],
439
                        $categories[$path4],
440
                        $categories[$path6]
441
                    );
442
        $mockSubject->expects($this->any())
443
                    ->method('getRootCategory')
444
                    ->willReturn($categories[$path1]);
445
        $mockSubject->expects($this->once())
446
                    ->method('getStoreViewCode')
447
                    ->with(StoreViewCodes::ADMIN)
448
                    ->willReturn($storeViewCode);
449
        $mockSubject->expects($this->once())
450
                    ->method('storeIsActive')
451
                    ->with($storeViewCode)
452
                    ->willReturn(true);
453
        $mockSubject->expects($this->once())
454
                    ->method('getEntityIdVisibilityIdMapping')
455
                    ->willReturn(VisibilityKeys::VISIBILITY_BOTH);
456
        $mockSubject->expects($this->any())
457
                    ->method('getRowStoreId')
458
                    ->willReturn($storeId = 1);
459
        $mockSubject->expects($this->any())
460
                    ->method('getCoreConfigData')
461
                    ->will(
462
                        $this->returnCallback(function ($arg1, $arg2) {
463
                            return $arg2;
464
                        })
465
                    );
466
       $mockSubject->expects(($this->exactly(4)))
467
                    ->method('getImportAdapter')
468
                    ->willReturn($mockImportAdapter);
469
470
        // mock the processor methods
471
        $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...
472
                    ->method('loadProduct')
473
                    ->with($sku)
474
                    ->willReturn(array(MemberNames::ENTITY_ID => $entityId));
475
        $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...
476
                    ->method('persistUrlRewrite')
477
                    ->withConsecutive(
478
                        array(
479
                            array(
480
                                MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
481
                                MemberNames::ENTITY_ID        => $entityId,
482
                                MemberNames::REQUEST_PATH     => sprintf('%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
483
                                MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s', $entityId),
484
                                MemberNames::REDIRECT_TYPE    => 0,
485
                                MemberNames::STORE_ID         => $storeId,
486
                                MemberNames::DESCRIPTION      => null,
487
                                MemberNames::IS_AUTOGENERATED => 1,
488
                                MemberNames::METADATA         => null,
489
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
490
                            )
491
                        ),
492
                        array(
493
                            array(
494
                                MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
495
                                MemberNames::ENTITY_ID        => $entityId,
496
                                MemberNames::REQUEST_PATH     => sprintf('men/tops-men/hoodies-and-sweatshirts-men/%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
497
                                MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s/category/5', $entityId),
498
                                MemberNames::REDIRECT_TYPE    => 0,
499
                                MemberNames::STORE_ID         => $storeId,
500
                                MemberNames::DESCRIPTION      => null,
501
                                MemberNames::IS_AUTOGENERATED => 1,
502
                                MemberNames::METADATA         => json_encode(array('category_id' => "5")),
503
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
504
                            )
505
                        ),
506
                        array(
507
                            array(
508
                                MemberNames::ENTITY_TYPE      => UrlRewriteObserver::ENTITY_TYPE,
509
                                MemberNames::ENTITY_ID        => $entityId,
510
                                MemberNames::REQUEST_PATH     => sprintf('collections/eco-friendly/%s.html', $row[$headers[ColumnKeys::URL_KEY]]),
511
                                MemberNames::TARGET_PATH      => sprintf('catalog/product/view/id/%s/category/7', $entityId),
512
                                MemberNames::REDIRECT_TYPE    => 0,
513
                                MemberNames::STORE_ID         => $storeId,
514
                                MemberNames::DESCRIPTION      => null,
515
                                MemberNames::IS_AUTOGENERATED => 1,
516
                                MemberNames::METADATA         => json_encode(array('category_id' => "7")),
517
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
518
                            )
519
                        )
520
                    )
521
                    ->willReturnOnConsecutiveCalls(1000, 1001, 1002);
522
        $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...
523
                    ->method('persistUrlRewriteProductCategory')
524
                    ->withConsecutive(
525
                        array(
526
                            array(
527
                                MemberNames::URL_REWRITE_ID   => 1001,
528
                                MemberNames::PRODUCT_ID       => $entityId,
529
                                MemberNames::CATEGORY_ID      => 5,
530
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
531
                            )
532
                        ),
533
                        array(
534
                            array(
535
                                MemberNames::URL_REWRITE_ID   => 1002,
536
                                MemberNames::PRODUCT_ID       => $entityId,
537
                                MemberNames::CATEGORY_ID      => 7,
538
                                EntityStatus::MEMBER_NAME     => EntityStatus::STATUS_CREATE
539
                            )
540
                        )
541
                    );
542
543
        // invoke the handle() method
544
        $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...
545
    }
546
}
547