Passed
Push — master ( 7f0a17...41e6e2 )
by Radosław
02:30
created

testFromApiRepresentation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
dl 18
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
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\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()
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 MTGRedAuctionDecorator($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 MTGRedAuctionDecorator($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 MTGRedAuctionDecorator($auction);
111
        $decorator->setPhotos($this->getTestPhotoArray());
112
    }
113
114
115 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...
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()
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...
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);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $decorator->fromApiRepre...tion($expectedArgument) (which targets Radowoj\Yaah\Decorators\...fromApiRepresentation()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
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...
152
    }
153
154
155
}
156