1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
4
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
5
|
|
|
use Behat\Gherkin\Node\TableNode; |
6
|
|
|
use DateTimeImmutable; |
7
|
|
|
use hiqdev\php\billing\action\Action; |
8
|
|
|
use hiqdev\php\billing\charge\Charge; |
9
|
|
|
use hiqdev\php\billing\customer\Customer; |
10
|
|
|
use hiqdev\php\billing\price\SinglePrice; |
11
|
|
|
use hiqdev\php\billing\target\Target; |
12
|
|
|
use hiqdev\php\billing\type\Type; |
13
|
|
|
use hiqdev\php\units\Quantity; |
14
|
|
|
use Money\Currency; |
15
|
|
|
use Money\Money; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Defines application features from the specific context. |
19
|
|
|
*/ |
20
|
|
|
class FeatureContext implements Context |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Initializes context. |
24
|
|
|
*/ |
25
|
|
|
public function __construct() |
26
|
|
|
{ |
27
|
|
|
$this->customer = new Customer(null, 'somebody'); |
|
|
|
|
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @Given /(\S+) (\S+) price is ([0-9.]+) (\w+) per ([0-9.]+) (\w+)/ |
32
|
|
|
*/ |
33
|
|
|
public function price($target, $type, $sum, $currency, $amount, $unit) |
34
|
|
|
{ |
35
|
|
|
$type = new Type(Type::ANY, $type); |
36
|
|
|
$target = new Target(Target::ANY, $target); |
37
|
|
|
$quantity = Quantity::create($unit, $amount); |
38
|
|
|
$sum = new Money($sum*100, new Currency($currency)); |
39
|
|
|
$this->price = new SinglePrice(null, $type, $target, null, $quantity, $sum); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @Given /action is (\S+) (\w+) ([0-9.]+) (\S+)/ |
44
|
|
|
*/ |
45
|
|
|
public function action($target, $type, $amount, $unit) |
46
|
|
|
{ |
47
|
|
|
$type = new Type(Type::ANY, $type); |
48
|
|
|
$target = new Target(Target::ANY, $target); |
49
|
|
|
$quantity = Quantity::create($unit, $amount); |
50
|
|
|
$time = new DateTimeImmutable(); |
51
|
|
|
$this->action = new Action(null, $type, $target, $quantity, $this->customer, $time); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @Given /formula (.+)/ |
56
|
|
|
*/ |
57
|
|
|
public function formula($formula) |
58
|
|
|
{ |
59
|
|
|
$this->formula = $formula; |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @When /date is ([0-9.-]+)/ |
64
|
|
|
*/ |
65
|
|
|
public function dateIs($date) |
66
|
|
|
{ |
67
|
|
|
$this->date = $date; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @Then /first charge is (\S+)? ?([0-9.]+)? ?([A-Z]{3})?/ |
72
|
|
|
*/ |
73
|
|
|
public function firstCharge($type = null, $sum = null, $currency = null) |
74
|
|
|
{ |
75
|
|
|
$this->charge(1, $type, $sum, $currency); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @Then /second charge is (\S+)? ?([0-9.]+)? ?([A-Z]{3})?/ |
80
|
|
|
*/ |
81
|
|
|
public function secondCharge($type = null, $sum = null, $currency = null) |
82
|
|
|
{ |
83
|
|
|
$this->charge(2, $type, $sum, $currency); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @Then /third charge is (\S+)? ?([0-9.]+)? ?([A-Z]{3})?/ |
88
|
|
|
*/ |
89
|
|
|
public function thirdCharge($type = null, $sum = null, $currency = null) |
90
|
|
|
{ |
91
|
|
|
$this->charge(3, $type, $sum, $currency); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function charge($no, $type, $sum = null, $currency = null) |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
var_dump($this->formula); |
|
|
|
|
97
|
|
|
var_dump($this->date); |
98
|
|
|
var_dump($type); |
99
|
|
|
var_dump($sum); |
100
|
|
|
var_dump($currency); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.