Code Duplication    Length = 34-36 lines in 2 locations

tests/Unit/Client/Product/ProductParserTest.php 2 locations

@@ 28-61 (lines=34) @@
25
     * @test
26
     * @dataProvider getProductJsonData
27
     */
28
    public function buildFromJson($json, $data)
29
    {
30
        $categoryBuilderMock =  Mockery::mock(CategoryBuilderInterface::class);
31
        $imageBuilderMock =  Mockery::mock(ImageBuilderInterface::class);
32
        $variantBuilderMock =  Mockery::mock(VariantBuilderInterface::class);
33
34
        foreach ($data as $product) {
35
            $categoryBuilderMock->shouldReceive('buildFromArray')
36
                ->with(($product['categories']))->once()->andReturn(new CategoryCollection());
37
            $imageBuilderMock->shouldReceive('buildFromArray')
38
                ->with(($product['imageLookupKeys']))->once()->andReturn(new ImageCollection());
39
            $variantBuilderMock->shouldReceive('buildFromArray')
40
                ->with(($product['variants']))->once()->andReturn(new VariantCollection());
41
        }
42
43
        $builder =  new ProductBuilder($categoryBuilderMock, $imageBuilderMock, $variantBuilderMock);
44
        $products = $builder->buildFromJson($json);
45
46
        foreach ($products as $index => $product) {
47
            self::assertInstanceOf(Product::class, $product);
48
            self::assertSame($data[$index]['uuid'], (string) $product->getUuid());
49
            self::assertInstanceOf(CategoryCollection::class, $product->getCategories());
50
            self::assertSame($data[$index]['name'], $product->getName());
51
            self::assertSame($data[$index]['description'], $product->getDescription());
52
            self::assertInstanceOf(ImageCollection::class, $product->getImageLookupKeys());
53
            self::assertInstanceOf(VariantCollection::class, $product->getVariants());
54
            self::assertSame($data[$index]['externalReference'], $product->getExternalReference());
55
            self::assertSame($data[$index]['etag'], $product->getEtag());
56
            self::assertEquals(new DateTime($data[$index]['updated']), $product->getUpdatedAt());
57
            self::assertSame($data[$index]['updatedBy'], (string) $product->getUpdatedBy());
58
            self::assertEquals(new DateTime($data[$index]['created']), $product->getCreatedAt());
59
            self::assertSame((float)$data[$index]['vatPercentage'], $product->getVatPercentage());
60
        }
61
    }
62
63
    /**
64
     * @test
@@ 67-102 (lines=36) @@
64
     * @test
65
     * @dataProvider getProductArrayData
66
     */
67
    public function buildFromArray($data)
68
    {
69
        $categoryBuilderMock =  Mockery::mock(CategoryBuilderInterface::class);
70
        $imageBuilderMock =  Mockery::mock(ImageBuilderInterface::class);
71
        $variantBuilderMock =  Mockery::mock(VariantBuilderInterface::class);
72
73
        foreach ($data as $product) {
74
            $categoryBuilderMock->shouldReceive('buildFromArray')
75
                ->with(($product['categories']))->once()->andReturn(new CategoryCollection());
76
            $imageBuilderMock->shouldReceive('buildFromArray')
77
                ->with(($product['imageLookupKeys']))->once()->andReturn(new ImageCollection());
78
            $variantBuilderMock->shouldReceive('buildFromArray')
79
                ->with(($product['variants']))->once()->andReturn(new VariantCollection());
80
        }
81
82
        $builder =  new ProductBuilder($categoryBuilderMock, $imageBuilderMock, $variantBuilderMock);
83
        $products = $builder->buildFromArray($data);
84
85
        $index = 0;
86
        foreach ($products->getAll() as $product) {
87
            self::assertInstanceOf(Product::class, $product);
88
            self::assertSame($data[$index]['uuid'], (string) $product->getUuid());
89
            self::assertInstanceOf(CategoryCollection::class, $product->getCategories());
90
            self::assertSame($data[$index]['name'], $product->getName());
91
            self::assertSame($data[$index]['description'], $product->getDescription());
92
            self::assertInstanceOf(ImageCollection::class, $product->getImageLookupKeys());
93
            self::assertInstanceOf(VariantCollection::class, $product->getVariants());
94
            self::assertSame($data[$index]['externalReference'], $product->getExternalReference());
95
            self::assertSame($data[$index]['etag'], $product->getEtag());
96
            self::assertEquals(new DateTime($data[$index]['updated']), $product->getUpdatedAt());
97
            self::assertSame($data[$index]['updatedBy'], (string) $product->getUpdatedBy());
98
            self::assertEquals(new DateTime($data[$index]['created']), $product->getCreatedAt());
99
            self::assertSame((float)$data[$index]['vatPercentage'], $product->getVatPercentage());
100
            $index++;
101
        }
102
    }
103
104
    public function getProductJsonData(): array
105
    {