|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* PHP Billing Library |
|
4
|
|
|
* |
|
5
|
|
|
* @link https://github.com/hiqdev/php-billing |
|
6
|
|
|
* @package php-billing |
|
7
|
|
|
* @license BSD-3-Clause |
|
8
|
|
|
* @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/) |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace hiqdev\php\billing\tests\unit\plan; |
|
12
|
|
|
|
|
13
|
|
|
use hiqdev\php\billing\action\SimpleAction; |
|
14
|
|
|
use hiqdev\php\billing\charge\Charge; |
|
15
|
|
|
use hiqdev\php\units\Quantity; |
|
16
|
|
|
|
|
17
|
|
|
class PlanTest extends \PHPUnit\Framework\TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
protected function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->plan = CertificatePlan::get(); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testCalculateCharge() |
|
25
|
|
|
{ |
|
26
|
|
|
foreach ($this->plan->types as $type) { |
|
27
|
|
|
foreach ($this->plan->targets as $target) { |
|
28
|
|
|
foreach ([1, 2, 3] as $years) { |
|
29
|
|
|
$usage = Quantity::month($years * 12); |
|
30
|
|
|
$action = new SimpleAction(null, $type, $target, $usage); |
|
31
|
|
|
$charges = $this->plan->calculateCharges($action); |
|
32
|
|
|
$this->checkCharges($action, $charges); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function checkCharges($action, $charges) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->assertTrue(is_array($charges)); |
|
41
|
|
|
$this->assertSame(1, count($charges)); |
|
42
|
|
|
$charge = reset($charges); |
|
43
|
|
|
$price = $this->plan->getRawPrice($action); |
|
44
|
|
|
$usage = $action->getQuantity(); |
|
45
|
|
|
$this->assertInstanceOf(Charge::class, $charge); |
|
46
|
|
|
$this->assertSame($action, $charge->getAction()); |
|
47
|
|
|
$this->assertSame($action->getType(), $charge->getType()); |
|
48
|
|
|
$this->assertSame($action->getTarget(), $charge->getTarget()); |
|
49
|
|
|
$this->assertTrue($price->equals($charge->getSum())); |
|
50
|
|
|
$this->assertTrue($usage->equals($charge->getUsage())); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|