Passed
Push — master ( d070fe...57713c )
by Radosław
02:55
created

DealTest::getExampleDeal()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
namespace Radowoj\Yaah\Journal;
4
5
use PHPUnit\Framework\TestCase;
6
use Radowoj\Yaah\Auction;
7
8
class DealTest extends TestCase
9
{
10
    protected function getExampleDeal()
11
    {
12
        return (object)[
13
            'dealEventId' => 1234,
14
            'dealEventType' => 1,
15
            'dealEventTime' => time(),
16
            'dealId' => 42,
17
            'dealTransactionId' => 4321,
18
            'dealSellerId' => 12345,
19
            'dealItemId' => 1234512345,
20
            'dealBuyerId' => 54321,
21
            'dealQuantity' => 2,
22
        ];
23
    }
24
25
26
    public function testMapFromObject()
27
    {
28
        $exampleDeal = $this->getExampleDeal();
29
        $deal = new Deal($exampleDeal);
30
31
        $this->assertSame($exampleDeal->dealEventId, $deal->getEventId());
32
        $this->assertSame($exampleDeal->dealEventType, $deal->getEventType());
33
        $this->assertSame($exampleDeal->dealId, $deal->getId());
34
        $this->assertSame($exampleDeal->dealTransactionId, $deal->getTransactionId());
35
        $this->assertSame($exampleDeal->dealSellerId, $deal->getSellerId());
36
        $this->assertSame($exampleDeal->dealItemId, $deal->getItemId());
37
        $this->assertSame($exampleDeal->dealBuyerId, $deal->getBuyerId());
38
        $this->assertSame($exampleDeal->dealQuantity, $deal->getQuantity());
39
    }
40
41
42
    public function testDealTimeFormatting()
43
    {
44
        $eventTime = time();
45
        $deal = new Deal((object)['dealEventTime' => $eventTime]);
46
47
        $this->assertSame(
48
            date('d.m.Y', $eventTime),
49
            $deal->getEventTime('d.m.Y'),
50
            'Custom formatting from argument'
51
        );
52
53
        $this->assertSame(
54
            date('Y-m-d H:i:s', $eventTime),
55
            $deal->getEventTime(),
56
            'Default formatting'
57
        );
58
    }
59
60
    /**
61
     * @expectedException InvalidArgumentException
62
     * @expectedExceptionMessage Original deal property name must start with "deal"
63
     */
64
    public function testExceptionOnNonDealProperty()
65
    {
66
        $deal = new Deal((object)['romanes' => 'eunt domus']);
0 ignored issues
show
Unused Code introduced by
$deal 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...
67
    }
68
69
70
    /**
71
     * @expectedException InvalidArgumentException
72
     * @expectedExceptionMessage Unknown Deal property: er
73
     */
74
    public function testExceptionOnInvalidDealProperty()
75
    {
76
        $deal = new Deal((object)['dealer' => 'Pinkman']);
0 ignored issues
show
Unused Code introduced by
$deal 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...
77
    }
78
79
80
    public function testTypeDetection()
81
    {
82
        $deal = new Deal((object)['dealEventType' => 1]);
83
        $this->assertTrue($deal->isTypeCreateDeal());
84
        $this->assertFalse($deal->isTypeCreatePostSaleForm());
85
        $this->assertFalse($deal->isTypeAbortPostSaleForm());
86
        $this->assertFalse($deal->isTypeFinishDeal());
87
88
        $deal = new Deal((object)['dealEventType' => 2]);
89
        $this->assertFalse($deal->isTypeCreateDeal());
90
        $this->assertTrue($deal->isTypeCreatePostSaleForm());
91
        $this->assertFalse($deal->isTypeAbortPostSaleForm());
92
        $this->assertFalse($deal->isTypeFinishDeal());
93
94
        $deal = new Deal((object)['dealEventType' => 3]);
95
        $this->assertFalse($deal->isTypeCreateDeal());
96
        $this->assertFalse($deal->isTypeCreatePostSaleForm());
97
        $this->assertTrue($deal->isTypeAbortPostSaleForm());
98
        $this->assertFalse($deal->isTypeFinishDeal());
99
100
        $deal = new Deal((object)['dealEventType' => 4]);
101
        $this->assertFalse($deal->isTypeCreateDeal());
102
        $this->assertFalse($deal->isTypeCreatePostSaleForm());
103
        $this->assertFalse($deal->isTypeAbortPostSaleForm());
104
        $this->assertTrue($deal->isTypeFinishDeal());
105
    }
106
107
}
108