|
1
|
|
|
<?php |
|
2
|
|
|
namespace OptimizelyPHPTest\Service\v2; |
|
3
|
|
|
|
|
4
|
|
|
use OptimizelyPHPTest\Service\v2\BaseServiceTest; |
|
5
|
|
|
use WebMarketingROI\OptimizelyPHP\OptimizelyApiClient; |
|
6
|
|
|
use WebMarketingROI\OptimizelyPHP\Exception; |
|
7
|
|
|
use WebMarketingROI\OptimizelyPHP\Result; |
|
8
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Plan as PlanResource; |
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Service\v2\Plan; |
|
10
|
|
|
|
|
11
|
|
|
class PlanTest extends BaseServiceTest |
|
12
|
|
|
{ |
|
13
|
|
|
public function testGet() |
|
14
|
|
|
{ |
|
15
|
|
|
// Mock 'OptimizelyApiClient' object to avoid real API calls |
|
16
|
|
|
$optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient') |
|
17
|
|
|
->disableOriginalConstructor() |
|
18
|
|
|
->getMock(); |
|
19
|
|
|
|
|
20
|
|
|
$result = new Result(array( |
|
21
|
|
|
'account_id' => '54321', |
|
22
|
|
|
'plan_name' => 'premium', |
|
23
|
|
|
'status' => 'active', |
|
24
|
|
|
'unit_of_measurement' => 'Impressions', |
|
25
|
|
|
'product_usages' => array( |
|
26
|
|
|
array( |
|
27
|
|
|
'allocation_term_in_months' => 6, |
|
28
|
|
|
'end_time' => '2019-12-31', |
|
29
|
|
|
'last_update_time' => '2019-06-01', |
|
30
|
|
|
'overage_cents_per_visitor' => 50, |
|
31
|
|
|
'product_name' => 'Product Name', |
|
32
|
|
|
'projects' => array(12345 => 10), |
|
33
|
|
|
'start_time' => '2019-06-01', |
|
34
|
|
|
'usage' => 1, |
|
35
|
|
|
'usage_allowance' => 5, |
|
36
|
|
|
), |
|
37
|
|
|
), |
|
38
|
|
|
), 200); |
|
39
|
|
|
|
|
40
|
|
|
$optimizelyApiClientMock->method('sendApiRequest') |
|
41
|
|
|
->willReturn($result); |
|
42
|
|
|
|
|
43
|
|
|
$planService = new Plan($optimizelyApiClientMock); |
|
44
|
|
|
|
|
45
|
|
|
$result = $planService->get(); |
|
46
|
|
|
$plan = $result->getPayload(); |
|
47
|
|
|
|
|
48
|
|
|
$this->assertTrue($plan instanceof PlanResource); |
|
49
|
|
|
$this->assertTrue($plan->getPlanName()=='premium'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testIntegration() |
|
53
|
|
|
{ |
|
54
|
|
|
if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) |
|
55
|
|
|
$this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set'); |
|
56
|
|
|
|
|
57
|
|
|
$credentials = $this->loadCredentialsFromFile(); |
|
58
|
|
|
|
|
59
|
|
|
$optimizelyClient = new OptimizelyApiClient($credentials, 'v2'); |
|
|
|
|
|
|
60
|
|
|
$this->assertTrue($optimizelyClient!=null); |
|
61
|
|
|
|
|
62
|
|
|
// Retrieve plan |
|
63
|
|
|
$result = $optimizelyClient->plan()->get(); |
|
|
|
|
|
|
64
|
|
|
$plan = $result->getPayload(); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertTrue($plan instanceof PlanResource); |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.