Passed
Push — master ( 4bb49a...f178ad )
by Radosław
04:16 queued 01:34
created

MTGAuctionDecoratorTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 103
Duplicated Lines 39.81 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 41
loc 103
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getTestPhotoArray() 0 6 1
A getTestArray() 0 19 1
A getTestFidArray() 0 20 1
A testFromArray() 14 14 1
A testToArray() 13 13 1
A testSetPhotos() 14 14 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Radowoj\Yaah\Decorators;
4
5
use PHPUnit\Framework\TestCase;
6
use Radowoj\Yaah\Auction;
7
use Radowoj\Yaah\Decorators\MTGAuctionDecorator;
8
use Radowoj\Yaah\Constants\AuctionTimespans;
9
use Radowoj\Yaah\Constants\Conditions;
10
use Radowoj\Yaah\Constants\SaleFormats;
11
use Radowoj\Yaah\Constants\ShippingPaidBy;
12
13
class MTGAuctionDecoratorTest extends TestCase
14
{
15
16
17
    protected function getTestPhotoArray()
18
    {
19
        return [
20
            __DIR__ . '/i.am.a.photo.file.txt'
21
        ];
22
    }
23
24
25
    protected function getTestArray()
26
    {
27
        return [
28
            'title' => 'Allegro test auction',
29
            'description' => 'Test auction description',
30
            'category' => 6092,
31
            'timespan' => AuctionTimespans::TIMESPAN_3_DAYS,
32
            'quantity' => 100,
33
            'country' => 1,
34
            'region' => 15,
35
            'city' => 'SomeCity',
36
            'postcode' => '12-345',
37
            'condition' => Conditions::CONDITION_NEW,
38
            'sale_format' => SaleFormats::SALE_FORMAT_SHOP,
39
            'buy_now_price' => 43,
40
            'shipping_paid_by' => ShippingPaidBy::SHIPPING_PAID_BY_BUYER,
41
            'post_package_priority_price' => 12,
42
        ];
43
    }
44
45
46
    protected function getTestFidArray()
47
    {
48
        return [
49
            1 => 'Allegro test auction',
50
            24 => 'Test auction description',
51
            2 => 6092,
52
            4 => 0,
53
            5 => 100,
54
            9 => 1,
55
            10 => 15,
56
            11 => 'SomeCity',
57
            32 => '12-345',
58
            20626 => 1,
59
            29 => 1,
60
            8 => 43,
61
            12 => 1,
62
            38 => 12,
63
        ];
64
65
    }
66
67
68 View Code Duplication
    public function testFromArray()
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...
69
    {
70
        $auction = $this->getMockBuilder(Auction::class)
71
            ->setMethods(['fromArray'])
72
            ->getMock();
73
74
        $auction->expects($this->once())
75
            ->method('fromArray')
76
            ->with($this->getTestFidArray())
77
            ->willReturn(null);
78
        $decorator = new MTGAuctionDecorator($auction);
79
80
        $decorator->fromArray($this->getTestArray());
81
    }
82
83
84 View Code Duplication
    public function testToArray()
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...
85
    {
86
        $auction = $this->getMockBuilder(Auction::class)
87
            ->setMethods(['toArray'])
88
            ->getMock();
89
90
        $auction->expects($this->once())
91
            ->method('toArray')
92
            ->willReturn($this->getTestFidArray());
93
        $decorator = new MTGAuctionDecorator($auction);
94
95
        $this->assertSame($this->getTestArray(), $decorator->toArray());
96
    }
97
98
99 View Code Duplication
    public function testSetPhotos()
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...
100
    {
101
        $auction = $this->getMockBuilder(Auction::class)
102
            ->setMethods(['setPhotos'])
103
            ->getMock();
104
105
        $auction->expects($this->once())
106
            ->method('setPhotos')
107
            ->with($this->getTestPhotoArray())
108
            ->willReturn(null);
109
110
        $decorator = new MTGAuctionDecorator($auction);
111
        $decorator->setPhotos($this->getTestPhotoArray());
112
    }
113
114
115
}
116