Completed
Pull Request — master (#11)
by Laurens
03:40
created

CashPaymentTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 36 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 9
loc 25
rs 10
c 0
b 0
f 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace LauLamanApps\IzettleApi\Tests\Unit\Api\Purchase\Payment;
6
7
use LauLamanApps\IzettleApi\API\Purchase\Payment\CashPayment;
8
use Money\Money;
9
use PHPUnit\Framework\TestCase;
10
use Ramsey\Uuid\Uuid;
11
12
/**
13
 * @small
14
 */
15
final class CashPaymentTest extends TestCase
16
{
17
    /**
18
     * @test
19
     * @dataProvider getAmounts
20
     */
21
    public function changedAmount($shouldPay, $payed)
22
    {
23
        $shouldReceiveChange = ($payed - $shouldPay);
24
25
        $payment = new CashPayment(Uuid::uuid1(), Money::EUR($shouldPay), Money::EUR($payed));
26
27
        self::assertSame($shouldReceiveChange, (int) $payment->getChangeAmount()->getAmount());
28
    }
29
30
    public function getAmounts(): array
31
    {
32
        return [
33
            'positive 1' => [200, 500],
34
            'positive 2' => [1000, 250],
35
            'negative 1' => [-100, 0],
36
            'negative 2' => [-1000, -1000],
37
        ];
38
    }
39
}
40