Passed
Branch master (168fd2)
by Dariusz
06:34
created

PaymentTest::testSetPriceFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 14
loc 14
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 9
nc 1
nop 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A PaymentTest::testCreateObjectWithInvalidFeeType() 0 6 1
1
<?php
2
3
namespace Plane\Shop\Tests;
4
5
use Money\Money;
6
use Plane\Shop\Payment;
7
use InvalidArgumentException;
8
9
/**
10
 * Payment test suite
11
 *
12
 * @author Dariusz Korsak <[email protected]>
13
 * @package Plane\Shop
14
 */
15
class PaymentTest extends \PHPUnit\Framework\TestCase
16
{
17
    use MoneyTrait;
18
19
    const CURRENCY = 'USD';
20
21
    const PAYMENT_INPUT = [
22
       'id'             => 1,
23
       'name'           => 'PayPal',
24
       'description'    => 'Payment with Paypal',
25
       'fee'            => 4
26
    ];
27
28 View Code Duplication
    public function testCreateObject()
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...
29
    {
30
        $payment = new Payment(self::PAYMENT_INPUT);
31
32
        $this->assertSame(self::PAYMENT_INPUT['id'], $payment->getId());
33
        $this->assertSame(self::PAYMENT_INPUT['name'], $payment->getName());
34
        $this->assertSame(self::PAYMENT_INPUT['description'], $payment->getDescription());
35
        $this->assertInstanceOf(Money::class, $payment->getFee($this->getMoney(10), self::CURRENCY));
36
    }
37
38
    public function testCreateIncompleteObject()
39
    {
40
        $input = self::PAYMENT_INPUT;
41
        unset($input['fee']);
42
43
        $this->expectException(InvalidArgumentException::class);
44
45
        $payment = new Payment($input);
0 ignored issues
show
Unused Code introduced by
$payment 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...
46
    }
47
48
    public function testCreateObjectWithInvalidFeeType()
49
    {
50
        $this->expectException(InvalidArgumentException::class);
51
52
        $payment = new Payment(self::PAYMENT_INPUT, 'newfeetype');
0 ignored issues
show
Unused Code introduced by
$payment 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...
53
    }
54
55 View Code Duplication
    public function testFixedFee()
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...
56
    {
57
        $payment = new Payment(self::PAYMENT_INPUT, Payment::FEE_FIXED);
58
        
59
        $fee = $payment->getFee($this->getMoney(10), self::CURRENCY);
60
 
61
        $this->assertEquals(4.00, $this->getAmount($fee));
62
    }
63
64 View Code Duplication
    public function testPercentageFee()
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...
65
    {
66
        $payment = new Payment(self::PAYMENT_INPUT, Payment::FEE_PERCENTAGE);
67
68
        $fee = $payment->getFee($this->getMoney(10), self::CURRENCY);
69
70
        $this->assertEquals(0.40, $this->getAmount($fee));
71
    }
72
}
73