Passed
Push — master ( 8ae622...d1f72e )
by Radosław
02:25
created

AuctionArrayMapDecoratorTest::testToArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace Radowoj\Yaah\Decorators;
4
5
use PHPUnit\Framework\TestCase;
6
use Radowoj\Yaah\Auction;
7
use Radowoj\Yaah\Decorators\AuctionArrayMapDecorator;
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 AuctionArrayMapDecoratorTest 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
    protected function getTestMap()
68
    {
69
        return [
70
            'title' => 1,
71
            'description' => 24,
72
            'category' => 2,
73
            'timespan' => 4,
74
            'quantity' => 5,
75
            'country' => 9,
76
            'region' => 10,
77
            'city' => 11,
78
            'postcode' => 32,
79
            'condition' => 20626,
80
            'sale_format' => 29,
81
            'buy_now_price' => 8,
82
            'shipping_paid_by' => 12,
83
            'post_package_priority_price' => 38,
84
        ];
85
    }
86
87
88
    protected function getDecorator(Auction $auction)
89
    {
90
        $decorator = $this->getMockForAbstractClass(AuctionArrayMapDecorator::class, [
91
            $auction
92
        ]);
93
94
        $decorator->expects($this->any())
95
            ->method('getMap')
96
            ->willReturn(
97
                $this->getTestMap()
98
            );
99
100
        return $decorator;
101
    }
102
103
104 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...
105
    {
106
        $auction = $this->getMockBuilder(Auction::class)
107
            ->setMethods(['fromArray'])
108
            ->getMock();
109
110
        $auction->expects($this->once())
111
            ->method('fromArray')
112
            ->with($this->getTestFidArray())
113
            ->willReturn(null);
114
115
        $decorator = $this->getDecorator($auction);
116
117
        $decorator->fromArray($this->getTestArray());
118
    }
119
120
121 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...
122
    {
123
        $auction = $this->getMockBuilder(Auction::class)
124
            ->setMethods(['toArray'])
125
            ->getMock();
126
127
        $auction->expects($this->once())
128
            ->method('toArray')
129
            ->willReturn($this->getTestFidArray());
130
131
        $decorator = $this->getDecorator($auction);
132
133
        $this->assertSame($this->getTestArray(), $decorator->toArray());
134
    }
135
136
137
138 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...
139
    {
140
        $auction = $this->getMockBuilder(Auction::class)
141
            ->setMethods(['setPhotos'])
142
            ->getMock();
143
144
        $auction->expects($this->once())
145
            ->method('setPhotos')
146
            ->with($this->getTestPhotoArray())
147
            ->willReturn(null);
148
149
        $decorator = $this->getDecorator($auction);
150
        $decorator->setPhotos($this->getTestPhotoArray());
151
    }
152
153
154 View Code Duplication
    public function testToApiRepresentation()
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...
155
    {
156
        $expectedResult = [
157
            'whatever' => 'just testing if it is forwarded correctly'
158
        ];
159
160
        $auction = $this->getMockBuilder(Auction::class)
161
            ->setMethods(['toApiRepresentation'])
162
            ->getMock();
163
164
        $auction->expects($this->once())
165
            ->method('toApiRepresentation')
166
            ->willReturn($expectedResult);
167
168
        $decorator = $this->getDecorator($auction);
169
        $result = $decorator->toApiRepresentation();
170
        $this->assertSame($expectedResult, $result);
171
    }
172
173
174 View Code Duplication
    public function testFromApiRepresentation()
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...
175
    {
176
        $expectedArgument = [
177
            'whatever' => 'just testing if it is forwarded correctly'
178
        ];
179
180
        $auction = $this->getMockBuilder(Auction::class)
181
            ->setMethods(['fromApiRepresentation'])
182
            ->getMock();
183
184
        $auction->expects($this->once())
185
            ->method('fromApiRepresentation')
186
            ->with($this->equalTo($expectedArgument));
187
188
189
        $decorator = $this->getDecorator($auction);
190
        $result = $decorator->fromApiRepresentation($expectedArgument);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
191
    }
192
193
}
194