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-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hiqdev\php\billing\tests\unit\tools; |
12
|
|
|
|
13
|
|
|
use hiqdev\php\billing\action\Action; |
14
|
|
|
use hiqdev\php\billing\charge\Generalizer; |
15
|
|
|
use hiqdev\php\billing\order\Calculator; |
16
|
|
|
use hiqdev\php\billing\order\CalculatorInterface; |
17
|
|
|
use hiqdev\php\billing\order\Order; |
18
|
|
|
use hiqdev\php\billing\order\OrderInterface; |
19
|
|
|
use hiqdev\php\billing\tests\unit\plan\CertificatePlan; |
20
|
|
|
use hiqdev\php\billing\tools\Factory; |
21
|
|
|
use hiqdev\php\billing\customer\Customer; |
22
|
|
|
use hiqdev\php\billing\customer\CustomerFactory; |
23
|
|
|
use hiqdev\php\billing\type\Type; |
24
|
|
|
use hiqdev\php\billing\type\TypeFactory; |
25
|
|
|
use hiqdev\php\billing\target\Target; |
26
|
|
|
use hiqdev\php\billing\target\TargetFactory; |
27
|
|
|
use hiqdev\php\billing\plan\Plan; |
28
|
|
|
use hiqdev\php\billing\plan\PlanFactory; |
29
|
|
|
use hiqdev\php\billing\price\PriceInterface; |
30
|
|
|
use hiqdev\php\billing\price\PriceFactory; |
31
|
|
|
use hiqdev\php\billing\price\SinglePrice; |
32
|
|
|
|
33
|
|
|
class FactoryTest extends \PHPUnit\Framework\TestCase |
34
|
|
|
{ |
35
|
|
|
private $unit = 'items'; |
36
|
|
|
private $currency = 'USD'; |
37
|
|
|
|
38
|
|
|
private $user = 'user'; |
39
|
|
|
private $reseller = 'reseller'; |
40
|
|
|
private $plan = 'plan'; |
41
|
|
|
|
42
|
|
|
private $type = 'type'; |
43
|
|
|
private $typeId = 'type-id'; |
44
|
|
|
|
45
|
|
|
private $priceId = 'price-id'; |
46
|
|
|
private $priceSum = '11.99'; |
47
|
|
|
|
48
|
|
|
private $target = 'target'; |
49
|
|
|
private $targetId = 'target-id'; |
50
|
|
|
|
51
|
|
|
protected function setUp() |
52
|
|
|
{ |
53
|
|
|
$this->factory = new Factory([ |
|
|
|
|
54
|
|
|
'type' => new TypeFactory(), |
55
|
|
|
'plan' => new PlanFactory(), |
56
|
|
|
'price' => new PriceFactory([], SinglePrice::class), |
57
|
|
|
'target' => new TargetFactory(), |
58
|
|
|
'customer' => new CustomerFactory(), |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testGetCustomer() |
63
|
|
|
{ |
64
|
|
|
$c1 = $this->factory->get('customer', ['login' => $this->user, 'seller' => $this->reseller]); |
65
|
|
|
$c2 = $this->factory->get('customer', ['login' => $this->user, 'seller' => $this->reseller]); |
66
|
|
|
$c3 = $this->factory->get('customer', ['login' => $this->user]); |
67
|
|
|
$c4 = $this->factory->get('customer', $this->user); |
68
|
|
|
$c5 = $this->factory->find('customer', [$this->user]); |
69
|
|
|
$this->assertInstanceOf(Customer::class, $c1); |
70
|
|
|
$this->assertSame($this->user, $c1->getLogin()); |
71
|
|
|
$this->assertSame($this->reseller, $c1->getSeller()->getLogin()); |
72
|
|
|
$this->assertSame($c1, $c2); |
73
|
|
|
$this->assertSame($c2, $c3); |
74
|
|
|
$this->assertSame($c3, $c4); |
75
|
|
|
$this->assertSame($c4, $c5); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testGetType() |
79
|
|
|
{ |
80
|
|
|
$t1 = $this->factory->get('type', ['id' => $this->typeId, 'name' => $this->type]); |
81
|
|
|
$t2 = $this->factory->get('type', ['id' => $this->typeId, 'name' => $this->type]); |
82
|
|
|
$t3 = $this->factory->get('type', ['id' => $this->typeId]); |
83
|
|
|
$t4 = $this->factory->get('type', $this->type); |
84
|
|
|
$t5 = $this->factory->find('type', [$this->type]); |
85
|
|
|
$this->assertInstanceOf(Type::class, $t1); |
86
|
|
|
$this->assertSame($this->type, $t1->getName()); |
87
|
|
|
$this->assertSame($this->typeId, $t1->getId()); |
88
|
|
|
$this->assertSame($t1, $t2); |
89
|
|
|
$this->assertSame($t1, $t3); |
90
|
|
|
$this->assertSame($t1, $t4); |
91
|
|
|
$this->assertSame($t1, $t5); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testGetTarget() |
95
|
|
|
{ |
96
|
|
|
$t1 = $this->factory->get('target', ['id' => $this->targetId, 'name' => $this->target, 'type' => 'simple']); |
97
|
|
|
$t2 = $this->factory->get('target', ['id' => $this->targetId, 'name' => $this->target, 'type' => 'simple']); |
98
|
|
|
$t3 = $this->factory->get('target', ['id' => $this->targetId]); |
99
|
|
|
$t4 = $this->factory->get('target', $this->targetId); |
100
|
|
|
$t5 = $this->factory->find('target', [$this->targetId]); |
101
|
|
|
$this->assertInstanceOf(Target::class, $t1); |
102
|
|
|
$this->assertSame($this->target, $t1->getName()); |
103
|
|
|
$this->assertSame($this->targetId, $t1->getId()); |
104
|
|
|
$this->assertSame($t1, $t2); |
105
|
|
|
$this->assertSame($t1, $t3); |
106
|
|
|
$this->assertSame($t1, $t4); |
107
|
|
|
$this->assertSame($t1, $t5); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testGetPlan() |
111
|
|
|
{ |
112
|
|
|
$p1 = $this->factory->get('plan', ['name' => $this->plan, 'seller' => $this->reseller]); |
113
|
|
|
$p2 = $this->factory->get('plan', ['name' => $this->plan, 'seller' => $this->reseller]); |
114
|
|
|
$p3 = $this->factory->get('plan', ['name' => $this->plan]); |
115
|
|
|
$p4 = $this->factory->get('plan', $this->plan); |
116
|
|
|
$p5 = $this->factory->find('plan', [$this->plan]); |
117
|
|
|
$this->assertInstanceOf(Plan::class, $p1); |
118
|
|
|
$this->assertSame($this->plan, $p1->getName()); |
119
|
|
|
$this->assertSame($this->reseller, $p1->getSeller()->getLogin()); |
120
|
|
|
$this->assertSame($p1, $p2); |
121
|
|
|
$this->assertSame($p2, $p3); |
122
|
|
|
$this->assertSame($p3, $p4); |
123
|
|
|
$this->assertSame($p4, $p5); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
public function testGetPrice() |
127
|
|
|
{ |
128
|
|
|
$p1 = $this->factory->get('price', [ |
129
|
|
|
'id' => $this->priceId, |
130
|
|
|
'type' => $this->type, |
131
|
|
|
'target' => $this->targetId, |
132
|
|
|
'price' => $this->priceSum . ' ' . $this->currency, |
133
|
|
|
'prepaid' => '0 ' . $this->unit, |
134
|
|
|
'currency' => $this->currency, |
135
|
|
|
]); |
136
|
|
|
$p2 = $this->factory->get('price', ['id' => $this->priceId, 'target' => $this->targetId]); |
137
|
|
|
$p3 = $this->factory->get('price', ['id' => $this->priceId]); |
138
|
|
|
$p4 = $this->factory->get('price', $this->priceId); |
139
|
|
|
$p5 = $this->factory->find('price', [$this->priceId]); |
140
|
|
|
$this->assertInstanceOf(PriceInterface::class, $p1); |
141
|
|
|
$this->assertSame($this->priceId, $p1->getId()); |
142
|
|
|
$this->assertSame($this->type, $p1->getType()->getName()); |
143
|
|
|
$this->assertSame($this->targetId, $p1->getTarget()->getId()); |
144
|
|
|
$this->assertSame($this->unit, $p1->getPrepaid()->getUnit()->getName()); |
145
|
|
|
$this->assertEquals($this->priceSum*100, $p1->getPrice()->getAmount()); |
146
|
|
|
$this->assertSame($p1, $p2); |
147
|
|
|
$this->assertSame($p1, $p3); |
148
|
|
|
$this->assertSame($p1, $p4); |
149
|
|
|
$this->assertSame($p1, $p5); |
150
|
|
|
} |
151
|
|
|
} |
152
|
|
|
|