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\Services; |
23
|
|
|
|
24
|
|
|
use App\Entity\Parts\Part; |
25
|
|
|
use App\Entity\PriceInformations\Orderdetail; |
26
|
|
|
use App\Entity\PriceInformations\Pricedetail; |
27
|
|
|
use App\Services\AmountFormatter; |
28
|
|
|
use App\Services\PricedetailHelper; |
29
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
30
|
|
|
|
31
|
|
|
class PricedetailHelperTest extends WebTestCase |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var AmountFormatter |
35
|
|
|
*/ |
36
|
|
|
protected $service; |
37
|
|
|
|
38
|
|
|
public function setUp() |
39
|
|
|
{ |
40
|
|
|
parent::setUp(); |
41
|
|
|
//Get an service instance. |
42
|
|
|
self::bootKernel(); |
43
|
|
|
$this->service = self::$container->get(PricedetailHelper::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function maxDiscountAmountDataProvider() |
47
|
|
|
{ |
48
|
|
|
$part = new Part(); |
49
|
|
|
yield [$part, null, 'Part without any orderdetails failed!']; |
50
|
|
|
|
51
|
|
|
//Part with empty orderdetails |
52
|
|
|
$part = new Part(); |
53
|
|
|
$orderdetail = new Orderdetail(); |
54
|
|
|
$part->addOrderdetail($orderdetail); |
55
|
|
|
yield [$part, null, 'Part with one empty orderdetail failed!']; |
56
|
|
|
|
57
|
|
|
$part = new Part(); |
58
|
|
|
$orderdetail = new Orderdetail(); |
59
|
|
|
$part->addOrderdetail($orderdetail); |
60
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setMinDiscountQuantity(1)); |
61
|
|
|
yield [$part, 1.0, 'Part with one pricedetail failed!']; |
62
|
|
|
|
63
|
|
|
$part = new Part(); |
64
|
|
|
$orderdetail = new Orderdetail(); |
65
|
|
|
$part->addOrderdetail($orderdetail); |
66
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setMinDiscountQuantity(1)); |
67
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setMinDiscountQuantity(2)); |
68
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setMinDiscountQuantity(1.5)); |
69
|
|
|
yield [$part, 2.0, 'Part with multiple pricedetails failed!']; |
70
|
|
|
|
71
|
|
|
$part = new Part(); |
72
|
|
|
$orderdetail = new Orderdetail(); |
73
|
|
|
$orderdetail2 = new Orderdetail(); |
74
|
|
|
$part->addOrderdetail($orderdetail); |
75
|
|
|
$part->addOrderdetail($orderdetail2); |
76
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setMinDiscountQuantity(1)); |
77
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setMinDiscountQuantity(2)); |
78
|
|
|
$orderdetail->addPricedetail((new Pricedetail())->setMinDiscountQuantity(1.5)); |
79
|
|
|
$orderdetail2->addPricedetail((new Pricedetail())->setMinDiscountQuantity(10)); |
80
|
|
|
|
81
|
|
|
yield [$part, 10.0, 'Part with multiple orderdetails failed']; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @dataProvider maxDiscountAmountDataProvider |
86
|
|
|
*/ |
87
|
|
|
public function testGetMaxDiscountAmount(Part $part, ?float $expected_result, string $message) |
88
|
|
|
{ |
89
|
|
|
$this->assertEquals($expected_result, $this->service->getMaxDiscountAmount($part), $message); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.