Passed
Push — master ( d286b7...24e4a5 )
by Jan
04:36
created

PricedetailTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 72
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetPricePerUnit() 0 14 1
A testGetPriceRelatedQuantity() 0 26 1
A testGetMinDiscountQuantity() 0 26 1
1
<?php
2
/**
3
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
4
 *
5
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
20
 */
21
22
namespace App\Tests\Entity\PriceSystem;
23
24
use App\Entity\Parts\Part;
25
use App\Entity\PriceInformations\Orderdetail;
26
use App\Entity\PriceInformations\Pricedetail;
27
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
29
class PricedetailTest extends TestCase
30
{
31
    public function testGetPricePerUnit()
32
    {
33
        $pricedetail = new Pricedetail();
34
        $pricedetail->setPrice('100.234');
35
36
        $this->assertEquals('100.23400', $pricedetail->getPricePerUnit());
37
38
        $pricedetail->setPriceRelatedQuantity('2.3');
0 ignored issues
show
Bug introduced by
'2.3' of type string is incompatible with the type double expected by parameter $new_price_related_quantity of App\Entity\PriceInformat...tPriceRelatedQuantity(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
        $pricedetail->setPriceRelatedQuantity(/** @scrutinizer ignore-type */ '2.3');
Loading history...
39
        $this->assertEquals('43.58000', $pricedetail->getPricePerUnit());
40
        $this->assertEquals('139.45600', $pricedetail->getPricePerUnit('3.2'));
41
42
        $pricedetail->setPrice('10000000.2345'); //Ten million
43
        $pricedetail->setPriceRelatedQuantity(1.234e9); //100 billion
44
        $this->assertEquals('0.00810', $pricedetail->getPricePerUnit());
45
    }
46
47
    public function testGetPriceRelatedQuantity()
48
    {
49
        $pricedetail = new Pricedetail();
50
        $part = $this->createMock(Part::class);
51
        $part->method('useFloatAmount')->willReturn(false);
52
        $orderdetail = $this->createMock(Orderdetail::class);
53
        $orderdetail->method('getPart')->willReturn($part);
54
55
        $part2 = $this->createMock(Part::class);
56
        $part2->method('useFloatAmount')->willReturn(true);
57
        $orderdetail2 = $this->createMock(Orderdetail::class);
58
        $orderdetail2->method('getPart')->willReturn($part2);
59
60
        //By default a price detail returns 1
61
        $this->assertEquals(1, $pricedetail->getPriceRelatedQuantity());
62
63
        $pricedetail->setOrderdetail($orderdetail);
64
        $pricedetail->setPriceRelatedQuantity(10.23);
65
        $this->assertEquals(10, $pricedetail->getPriceRelatedQuantity());
66
        //Price related quantity must not be zero!
67
        $pricedetail->setPriceRelatedQuantity(0.23);
68
        $this->assertEquals(1, $pricedetail->getPriceRelatedQuantity());
69
70
        //With an part that has an float amount unit, also values like 0.23 can be returned
71
        $pricedetail->setOrderdetail($orderdetail2);
72
        $this->assertEquals(0.23, $pricedetail->getPriceRelatedQuantity());
73
    }
74
75
    public function testGetMinDiscountQuantity()
76
    {
77
        $pricedetail = new Pricedetail();
78
        $part = $this->createMock(Part::class);
79
        $part->method('useFloatAmount')->willReturn(false);
80
        $orderdetail = $this->createMock(Orderdetail::class);
81
        $orderdetail->method('getPart')->willReturn($part);
82
83
        $part2 = $this->createMock(Part::class);
84
        $part2->method('useFloatAmount')->willReturn(true);
85
        $orderdetail2 = $this->createMock(Orderdetail::class);
86
        $orderdetail2->method('getPart')->willReturn($part2);
87
88
        //By default a price detail returns 1
89
        $this->assertEquals(1, $pricedetail->getMinDiscountQuantity());
90
91
        $pricedetail->setOrderdetail($orderdetail);
92
        $pricedetail->setMinDiscountQuantity(10.23);
93
        $this->assertEquals(10, $pricedetail->getMinDiscountQuantity());
94
        //Price related quantity must not be zero!
95
        $pricedetail->setMinDiscountQuantity(0.23);
96
        $this->assertEquals(1, $pricedetail->getMinDiscountQuantity());
97
98
        //With an part that has an float amount unit, also values like 0.23 can be returned
99
        $pricedetail->setOrderdetail($orderdetail2);
100
        $this->assertEquals(0.23, $pricedetail->getMinDiscountQuantity());
101
    }
102
}
103