1
|
|
|
<?php |
2
|
|
|
namespace OptimizelyPHPTest\Resource\v2; |
3
|
|
|
|
4
|
|
|
use PHPUnit_Framework_TestCase; |
5
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Plan; |
6
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\ProductUsage; |
7
|
|
|
|
8
|
|
|
class PlanTest extends PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function testCreateNewPlan() |
11
|
|
|
{ |
12
|
|
|
$plan = new Plan(); |
13
|
|
|
$plan->setAccountId('54321'); |
14
|
|
|
$plan->setPlanName('premium'); |
15
|
|
|
$plan->setStatus('active'); |
16
|
|
|
$plan->setUnitOfMeasurement('Impressions'); |
17
|
|
|
|
18
|
|
|
$productUsage = new ProductUsage(); |
19
|
|
|
$productUsage->setAllocationTermInMonths(6); |
20
|
|
|
$productUsage->setEndTime('2019-12-31'); |
21
|
|
|
$productUsage->setLastUpdateTime('2019-06-01'); |
22
|
|
|
$productUsage->setOverageCentsPerVisitor(50); |
23
|
|
|
$productUsage->setProductName('Product Name'); |
24
|
|
|
$productUsage->setProjects(['12345' => 10]); |
25
|
|
|
$productUsage->setStartTime('2019-06-01'); |
26
|
|
|
$productUsage->setUsage(1); |
27
|
|
|
$productUsage->setUsageAllowance(5); |
28
|
|
|
|
29
|
|
|
$plan->setProductUsages([$productUsage]); |
30
|
|
|
|
31
|
|
|
$this->assertEquals('54321', $plan->getAccountId()); |
32
|
|
|
$this->assertEquals('premium', $plan->getPlanName()); |
33
|
|
|
$this->assertEquals('active', $plan->getStatus()); |
34
|
|
|
$this->assertEquals('Impressions', $plan->getUnitOfMeasurement()); |
35
|
|
|
$usages = $plan->getProductUsages(); |
36
|
|
|
$this->assertEquals('Product Name', $usages[0]->getProductName()); |
37
|
|
|
$this->assertEquals(['12345' => 10], $usages[0]->getProjects()); |
38
|
|
|
|
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testCreateNewPlanWithOptions() |
42
|
|
|
{ |
43
|
|
|
$options = array( |
44
|
|
|
'account_id' => '54321', |
45
|
|
|
'plan_name' => 'premium', |
46
|
|
|
'status' => 'active', |
47
|
|
|
'unit_of_measurement' => 'Impressions', |
48
|
|
|
'product_usages' => array( |
49
|
|
|
array( |
50
|
|
|
'allocation_term_in_months' => 6, |
51
|
|
|
'end_time' => '2019-12-31', |
52
|
|
|
'last_update_time' => '2019-06-01', |
53
|
|
|
'overage_cents_per_visitor' => 50, |
54
|
|
|
'product_name' => 'Product Name', |
55
|
|
|
'projects' => array(12345 => 10), |
56
|
|
|
'start_time' => '2019-06-01', |
57
|
|
|
'usage' => 1, |
58
|
|
|
'usage_allowance' => 5, |
59
|
|
|
), |
60
|
|
|
), |
61
|
|
|
); |
62
|
|
|
|
63
|
|
|
$plan = new Plan($options); |
64
|
|
|
|
65
|
|
|
$this->assertEquals('54321', $plan->getAccountId()); |
66
|
|
|
$this->assertEquals('premium', $plan->getPlanName()); |
67
|
|
|
$this->assertEquals('active', $plan->getStatus()); |
68
|
|
|
$this->assertEquals('Impressions', $plan->getUnitOfMeasurement()); |
69
|
|
|
$usages = $plan->getProductUsages(); |
70
|
|
|
$this->assertEquals('Product Name', $usages[0]->getProductName()); |
71
|
|
|
$this->assertEquals(['12345' => 10], $usages[0]->getProjects()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testToArray() |
75
|
|
|
{ |
76
|
|
|
$curDate = date('Y-m-d H:i:s'); |
|
|
|
|
77
|
|
|
|
78
|
|
|
$options = array( |
79
|
|
|
'account_id' => '54321', |
80
|
|
|
'plan_name' => 'premium', |
81
|
|
|
'status' => 'active', |
82
|
|
|
'unit_of_measurement' => 'Impressions', |
83
|
|
|
'product_usages' => array( |
84
|
|
|
array( |
85
|
|
|
'allocation_term_in_months' => 6, |
86
|
|
|
'end_time' => '2019-12-31', |
87
|
|
|
'last_update_time' => '2019-06-01', |
88
|
|
|
'overage_cents_per_visitor' => 50, |
89
|
|
|
'product_name' => 'Product Name', |
90
|
|
|
'projects' => array(12345 => 10), |
91
|
|
|
'start_time' => '2019-06-01', |
92
|
|
|
'usage' => 1, |
93
|
|
|
'usage_allowance' => 5, |
94
|
|
|
), |
95
|
|
|
), |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$plan = new Plan($options); |
99
|
|
|
|
100
|
|
|
$this->assertEquals($options, $plan->toArray()); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.