Passed
Push — master ( 3e9959...0d684b )
by Dariusz
02:37
created

PaymentTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 45
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateObject() 0 12 1
A testPercentageFee() 0 7 1
A testSetPriceFormat() 0 14 1
1
<?php
2
3
namespace Plane\Shop\Tests;
4
5
use Plane\Shop\Payment;
6
use Plane\Shop\PriceFormat\EnglishFormat as PriceFormat;
7
8
/**
9
 * Payment test suite
10
 *
11
 * @author Dariusz Korsak <[email protected]>
12
 * @package Plane\Shop
13
 */
14
class PaymentTest extends \PHPUnit\Framework\TestCase
15
{
16
    protected $paymentInput = [
17
       'id'             => 1,
18
       'name'           => 'PayPal',
19
       'description'    => 'Payment with Paypal',
20
       'fee'            => 0.2
21
    ];
22
23
    public function testCreateObject()
24
    {
25
        $payment = new Payment($this->paymentInput);
26
        $payment->setFixed();
27
28
        $this->assertSame($this->paymentInput, [
29
            'id'                => $payment->getId(),
30
            'name'              => $payment->getName(),
31
            'description'       => $payment->getDescription(),
32
            'fee'               => $payment->getFee(10),
33
        ]);
34
    }
35
36
    public function testPercentageFee()
37
    {
38
        $payment = new Payment($this->paymentInput);
39
        $payment->setPercentage();
40
41
        $this->assertSame(2.0, $payment->getFee(10));
42
    }
43
44
    public function testSetPriceFormat()
45
    {
46
        $priceFormat = $this->getMockBuilder(PriceFormat::class)
47
            ->getMock();
48
        
49
        $priceFormat->expects($this->any())
50
            ->method('formatPrice')
51
            ->willReturn(2.00);
52
        
53
        $payment = new Payment($this->paymentInput);
54
        $payment->setPriceFormat($priceFormat);
55
        
56
        $this->assertSame(2.00, $payment->getFee(10));
57
    }
58
}
59