|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
|
4
|
|
|
use Behat\Gherkin\Node\PyStringNode; |
|
5
|
|
|
use Behat\Gherkin\Node\TableNode; |
|
6
|
|
|
use hiqdev\php\billing\action\Action; |
|
7
|
|
|
use hiqdev\php\billing\charge\Charge; |
|
8
|
|
|
use hiqdev\php\billing\customer\Customer; |
|
9
|
|
|
use hiqdev\php\billing\price\SinglePrice; |
|
10
|
|
|
use hiqdev\php\billing\target\Target; |
|
11
|
|
|
use hiqdev\php\billing\type\Type; |
|
12
|
|
|
use hiqdev\php\units\Quantity; |
|
13
|
|
|
use Money\Currency; |
|
14
|
|
|
use Money\Money; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Defines application features from the specific context. |
|
18
|
|
|
*/ |
|
19
|
|
|
class FeatureContext implements Context |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Initializes context. |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->customer = new Customer(null, 'somebody'); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @Given /(\S+) (\S+) price is ([0-9.]+) (\w+) per ([0-9.]+) (\w+)/ |
|
31
|
|
|
*/ |
|
32
|
|
|
public function priceIs($target, $type, $sum, $currency, $amount, $unit) |
|
33
|
|
|
{ |
|
34
|
|
|
$type = new Type(Type::ANY, $type); |
|
35
|
|
|
$target = new Target(Target::ANY, $target); |
|
36
|
|
|
$quantity = Quantity::create($unit, $amount); |
|
37
|
|
|
$sum = new Money($sum*100, new Currency($currency)); |
|
38
|
|
|
$this->price = new SinglePrice(null, $type, $target, null, $quantity, $sum); |
|
|
|
|
|
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @Given /action is (\S+) (\w+) ([0-9.]+) (\S+)/ |
|
43
|
|
|
*/ |
|
44
|
|
|
public function actionIs($target, $type, $amount, $unit) |
|
45
|
|
|
{ |
|
46
|
|
|
$type = new Type(Type::ANY, $type); |
|
47
|
|
|
$target = new Target(Target::ANY, $target); |
|
48
|
|
|
$quantity = Quantity::create($unit, $amount); |
|
49
|
|
|
$time = new DateTimeImmutable(); |
|
50
|
|
|
$this->action = new Action(null, $type, $target, $quantity, $this->customer, $time); |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @Given /formula is (.+)/ |
|
55
|
|
|
*/ |
|
56
|
|
|
public function formulaIs($formula) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->formula = $formula; |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @When /date is ([0-9.-]+)/ |
|
63
|
|
|
*/ |
|
64
|
|
|
public function dateIs($date) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->date = $date; |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @Then /(\w+) charge is (\S+)? ?([0-9.]+)? ?([A-Z]{3})?/ |
|
71
|
|
|
*/ |
|
72
|
|
|
public function chargeIs($numeral, $type = null, $sum = null, $currency = null) |
|
|
|
|
|
|
73
|
|
|
{ |
|
74
|
|
|
$no = $this->ensureNo($numeral); |
|
|
|
|
|
|
75
|
|
|
//var_dump($this->formula); |
|
|
|
|
|
|
76
|
|
|
//var_dump($this->date); |
|
|
|
|
|
|
77
|
|
|
//var_dump("$no $type $sum $currency"); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected $numerals = [ |
|
81
|
|
|
'first' => 1, |
|
82
|
|
|
'second' => 2, |
|
83
|
|
|
'third' => 3, |
|
84
|
|
|
'fourth' => 4, |
|
85
|
|
|
'fifth' => 5, |
|
86
|
|
|
]; |
|
87
|
|
|
|
|
88
|
|
|
public function ensureNo($numeral) |
|
89
|
|
|
{ |
|
90
|
|
|
if (empty($this->numerals[$numeral])) { |
|
91
|
|
|
throw new Exception("wrong numeral '$numeral'"); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $this->numerals[$numeral] - 1; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
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.