1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
namespace Radowoj\Yaah\Decorators;
|
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase;
|
6
|
|
|
use Radowoj\Yaah\Auction;
|
7
|
|
|
use Radowoj\Yaah\Decorators\MTGRedAuctionDecorator;
|
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 MTGRedAuctionDecoratorTest 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()
|
|
|
|
|
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 MTGRedAuctionDecorator($auction);
|
79
|
|
|
|
80
|
|
|
$decorator->fromArray($this->getTestArray());
|
81
|
|
|
}
|
82
|
|
|
|
83
|
|
|
|
84
|
|
View Code Duplication |
public function testToArray()
|
|
|
|
|
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 MTGRedAuctionDecorator($auction);
|
94
|
|
|
|
95
|
|
|
$this->assertSame($this->getTestArray(), $decorator->toArray());
|
96
|
|
|
}
|
97
|
|
|
|
98
|
|
|
|
99
|
|
View Code Duplication |
public function testSetPhotos()
|
|
|
|
|
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 MTGRedAuctionDecorator($auction);
|
111
|
|
|
$decorator->setPhotos($this->getTestPhotoArray());
|
112
|
|
|
}
|
113
|
|
|
|
114
|
|
|
|
115
|
|
View Code Duplication |
public function testToApiRepresentation()
|
|
|
|
|
116
|
|
|
{
|
117
|
|
|
$expectedResult = [
|
118
|
|
|
'whatever' => 'just testing if it is forwarded correctly'
|
119
|
|
|
];
|
120
|
|
|
|
121
|
|
|
$auction = $this->getMockBuilder(Auction::class)
|
122
|
|
|
->setMethods(['toApiRepresentation'])
|
123
|
|
|
->getMock();
|
124
|
|
|
|
125
|
|
|
$auction->expects($this->once())
|
126
|
|
|
->method('toApiRepresentation')
|
127
|
|
|
->willReturn($expectedResult);
|
128
|
|
|
|
129
|
|
|
$decorator = new MTGRedAuctionDecorator($auction);
|
130
|
|
|
$result = $decorator->toApiRepresentation();
|
131
|
|
|
$this->assertSame($expectedResult, $result);
|
132
|
|
|
}
|
133
|
|
|
|
134
|
|
|
|
135
|
|
View Code Duplication |
public function testFromApiRepresentation()
|
|
|
|
|
136
|
|
|
{
|
137
|
|
|
$expectedArgument = [
|
138
|
|
|
'whatever' => 'just testing if it is forwarded correctly'
|
139
|
|
|
];
|
140
|
|
|
|
141
|
|
|
$auction = $this->getMockBuilder(Auction::class)
|
142
|
|
|
->setMethods(['fromApiRepresentation'])
|
143
|
|
|
->getMock();
|
144
|
|
|
|
145
|
|
|
$auction->expects($this->once())
|
146
|
|
|
->method('fromApiRepresentation')
|
147
|
|
|
->with($this->equalTo($expectedArgument));
|
148
|
|
|
|
149
|
|
|
|
150
|
|
|
$decorator = new MTGRedAuctionDecorator($auction);
|
151
|
|
|
$result = $decorator->fromApiRepresentation($expectedArgument);
|
|
|
|
|
152
|
|
|
}
|
153
|
|
|
|
154
|
|
|
|
155
|
|
|
}
|
156
|
|
|
|
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.