Completed
Push — master ( 8b4718...61d59f )
by Oleg
02:27
created

ProjectsTest::testIntegration()   C

Complexity

Conditions 8
Paths 76

Size

Total Lines 106
Code Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 47
nc 76
nop 0
dl 0
loc 106
rs 5.2676
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Service\v2\Projects;
9
use WebMarketingROI\OptimizelyPHP\Resource\v2\Project;
10
11
class ProjectsTest extends BaseServiceTest
12
{
13
    public function testListAll()
14
    {
15
        // Mock 'OptimizelyApiClient' object to avoid real API calls
16
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
17
                            ->disableOriginalConstructor()
18
                            ->getMock();
19
20
        $curDate = date('Y-m-d H:i:s');
21
        
22
        $result = new Result(array(
23
                        array(
24
                            'id' => '1523456',
25
                            'account_id' => '54321',
26
                            'name' => 'Some Optimizely Project',
27
                            'created' => $curDate,
28
                            'last_modified' => $curDate,
29
                            'is_classic' => true,
30
                            'socket_token' => 'fwerw',            
31
                            'web_snippet' => array(
32
                                "enable_force_variation" => false,
33
                                "exclude_disabled_experiments" => false,
34
                                "exclude_names" => true,
35
                                "include_jquery" => true,
36
                                "ip_anonymization" => false,
37
                                "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
38
                                "library" => "jquery-1.11.3-trim",
39
                                "project_javascript" => "alert(\"Active Experiment\")",
40
                                "code_revision" => '123456',
41
                                "js_file_size" => 5004
42
                            )
43
                        )
44
                    ), 200);
45
                        
46
        $optimizelyApiClientMock->method('sendApiRequest')
47
                    ->willReturn($result);
48
        
49
        $projectsService = new Projects($optimizelyApiClientMock);
50
        
51
        $result = $projectsService->listAll();
52
        $projects = $result->getPayload();
53
        
54
        $this->assertTrue(count($projects)==1);
55
        $this->assertTrue($projects[0] instanceOf Project);
56
        $this->assertTrue($projects[0]->getName()=='Some Optimizely Project');        
57
    }
58
    
59
    /**
60
     * @expectedException Exception
61
     */
62
    public function testListAll_InvalidPage()
63
    {
64
        // Mock 'OptimizelyApiClient' object to avoid real API calls
65
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
66
                            ->disableOriginalConstructor()
67
                            ->getMock();
68
        
69
        $projectsService = new Projects($optimizelyApiClientMock);
70
        
71
        $result = $projectsService->listAll(-1, 25);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
72
    }
73
    
74
    /**
75
     * @expectedException Exception
76
     */
77
    public function testListAll_InvalidPerPage()
78
    {
79
        // Mock 'OptimizelyApiClient' object to avoid real API calls
80
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
81
                            ->disableOriginalConstructor()
82
                            ->getMock();
83
        
84
        $projectsService = new Projects($optimizelyApiClientMock);
85
        
86
        $result = $projectsService->listAll(1, 1000);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
87
    }
88
    
89
    public function testGet()
90
    {
91
        // Mock 'OptimizelyApiClient' object to avoid real API calls
92
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
93
                            ->disableOriginalConstructor()
94
                            ->getMock();
95
                
96
        $curDate = date('Y-m-d H:i:s');
97
        
98
        $result = new Result(array(
99
                            'id' => '1523456',
100
                            'account_id' => '54321',
101
                            'name' => 'Some Optimizely Project',
102
                            'created' => $curDate,
103
                            'last_modified' => $curDate,
104
                            'is_classic' => true,
105
                            'socket_token' => 'fwerw',            
106
                            'web_snippet' => array(
107
                                "enable_force_variation" => false,
108
                                "exclude_disabled_experiments" => false,
109
                                "exclude_names" => true,
110
                                "include_jquery" => true,
111
                                "ip_anonymization" => false,
112
                                "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
113
                                "library" => "jquery-1.11.3-trim",
114
                                "project_javascript" => "alert(\"Active Experiment\")",
115
                                "code_revision" => '123456',
116
                                "js_file_size" => 5004
117
                            )                        
118
                        ), 200);
119
        
120
        $optimizelyApiClientMock->method('sendApiRequest')
121
                    ->willReturn($result);
122
        
123
        $projectsService = new Projects($optimizelyApiClientMock);
124
        
125
        $result = $projectsService->get(1523456);
126
        $project = $result->getPayload();
127
        
128
        $this->assertTrue($project instanceOf Project);
129
        $this->assertTrue($project->getName()=='Some Optimizely Project');        
130
    }
131
    
132
    /**
133
     * @expectedException Exception
134
     */
135
    public function testGet_NotIntegerProjectId()
136
    {
137
        // Mock 'OptimizelyApiClient' object to avoid real API calls
138
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
139
                            ->disableOriginalConstructor()
140
                            ->getMock();
141
        
142
        $projectsService = new Projects($optimizelyApiClientMock);
143
        
144
        $result = $projectsService->get('1');
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
145
    }
146
    
147
    /**
148
     * @expectedException Exception
149
     */
150 View Code Duplication
    public function testGet_NegativeProjectId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
151
    {
152
        // Mock 'OptimizelyApiClient' object to avoid real API calls
153
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
154
                            ->disableOriginalConstructor()
155
                            ->getMock();
156
        
157
        $projectsService = new Projects($optimizelyApiClientMock);
158
        
159
        $result = $projectsService->get(-1);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
160
    }
161
    
162
    public function testCreate()
163
    {
164
        // Mock 'OptimizelyApiClient' object to avoid real API calls
165
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
166
                            ->disableOriginalConstructor()
167
                            ->getMock();
168
169
        $curDate = date('Y-m-d H:i:s');
0 ignored issues
show
Unused Code introduced by
$curDate is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
170
        
171
        $result = new Result(array(
172
                            "name" => "Test Project",
173
                            "account_id" => 12345,
174
                            "confidence_threshold" => 0.9,
175
                            "dcp_service_id" => 121234,
176
                            "platform" => "web",
177
                            "status" => "active",
178
                            "web_snippet" => array(
179
                              "enable_force_variation" => false,
180
                              "exclude_disabled_experiments" => false,
181
                              "exclude_names" => true,
182
                              "include_jquery" => true,
183
                              "ip_anonymization" => false,
184
                              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
185
                              "library" => "jquery-1.11.3-trim",
186
                              "project_javascript" => "alert(\"Active Experiment\")",
187
                              "code_revision" => 0,
188
                              "js_file_size" => 63495
189
                            ),
190
                            "created" => "2016-10-17T07:04:59.991Z",
191
                            "id" => 1000,
192
                            "is_classic" => true,
193
                            "last_modified" => "2016-10-17T07:04:59.991Z",
194
                            "socket_token" => "AABBCCDD~123456789"                   
195
                        ), 201);
196
        $optimizelyApiClientMock->method('sendApiRequest')
197
                    ->willReturn($result);
198
        
199
        $projectsService = new Projects($optimizelyApiClientMock);
200
        
201
        $project = new Project(array(
202
            "name" => "Test Project",
203
            "account_id" => 12345,
204
            "confidence_threshold" => 0.9,
205
            "dcp_service_id" => 121234,
206
            "platform" => "web",
207
            "status" => "active",
208
            "web_snippet" => array(
209
              "enable_force_variation" => false,
210
              "exclude_disabled_experiments" => false,
211
              "exclude_names" => true,
212
              "include_jquery" => true,
213
              "ip_anonymization" => false,
214
              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
215
              "library" => "jquery-1.11.3-trim",
216
              "project_javascript" => "alert(\"Active Experiment\")"
217
            )
218
        ));
219
        
220
        $result = $projectsService->create($project);
221
        $createdProject = $result->getPayload();
222
        
223
        $this->assertTrue($createdProject instanceOf Project);
224
        $this->assertTrue($createdProject->getName()=='Test Project');        
225
        $this->assertTrue($createdProject->getAccountId()==12345);        
226
    }
227
    
228
    /**
229
     * @expectedException Exception
230
     */
231 View Code Duplication
    public function testCreate_InvalidProject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
232
    {
233
        // Mock 'OptimizelyApiClient' object to avoid real API calls
234
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
235
                            ->disableOriginalConstructor()
236
                            ->getMock();
237
        
238
        $projectsService = new Projects($optimizelyApiClientMock);
239
        
240
        $result = $projectsService->create(1);
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a object<WebMarketingROI\O...HP\Resource\v2\Project>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
241
    }
242
    
243
    public function testUpdate()
244
    {
245
        // Mock 'OptimizelyApiClient' object to avoid real API calls
246
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
247
                            ->disableOriginalConstructor()
248
                            ->getMock();
249
250
        $curDate = date('Y-m-d H:i:s');
0 ignored issues
show
Unused Code introduced by
$curDate is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
251
        
252
        $result = new Result(array(
253
                            "name" => "Test Project",
254
                            "account_id" => 12345,
255
                            "confidence_threshold" => 0.9,
256
                            "dcp_service_id" => 121234,
257
                            "platform" => "web",
258
                            "status" => "active",
259
                            "web_snippet" => array(
260
                              "enable_force_variation" => false,
261
                              "exclude_disabled_experiments" => false,
262
                              "exclude_names" => true,
263
                              "include_jquery" => true,
264
                              "ip_anonymization" => false,
265
                              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
266
                              "library" => "jquery-1.11.3-trim",
267
                              "project_javascript" => "alert(\"Active Experiment\")",
268
                              "code_revision" => 0,
269
                              "js_file_size" => 63495
270
                            ),
271
                            "created" => "2016-10-17T07:04:59.999Z",
272
                            "id" => 1000,
273
                            "is_classic" => true,
274
                            "last_modified" => "2016-10-17T07:04:59.999Z",
275
                            "socket_token" => "AABBCCDD~123456789"
276
                        ), 200);
277
        
278
        $optimizelyApiClientMock->method('sendApiRequest')
279
                    ->willReturn($result);
280
        
281
        $projectsService = new Projects($optimizelyApiClientMock);
282
        
283
        $project = new Project(array(
284
            "confidence_threshold" => 0.9,
285
            "dcp_service_id" => 121234,
286
            "name" => "Test Project",
287
            "status" => "active",
288
            "web_snippet" => array(
289
              "enable_force_variation" => false,
290
              "exclude_disabled_experiments" => false,
291
              "exclude_names" => true,
292
              "include_jquery" => true,
293
              "ip_anonymization" => false,
294
              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
295
              "library" => "jquery-1.11.3-trim",
296
              "project_javascript" => "alert(\"Active Experiment\")"
297
            )
298
        ));
299
        
300
        $result = $projectsService->update(121234, $project);
301
        $updatedProject = $result->getPayload();
302
        
303
        $this->assertTrue($updatedProject instanceOf Project);
304
        $this->assertTrue($updatedProject->getName()=='Test Project');        
305
        $this->assertTrue($updatedProject->getAccountId()==12345);        
306
    }
307
    
308
    /**
309
     * @expectedException Exception
310
     */
311 View Code Duplication
    public function testUpdate_NotIntegerProjectId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
312
    {
313
        // Mock 'OptimizelyApiClient' object to avoid real API calls
314
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
315
                            ->disableOriginalConstructor()
316
                            ->getMock();
317
        
318
        $projectsService = new Projects($optimizelyApiClientMock);
319
        
320
        $project = new Project();
321
        
322
        $result = $projectsService->update('1000', $project);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
323
    }
324
    
325
    /**
326
     * @expectedException Exception
327
     */
328 View Code Duplication
    public function testUpdate_NegativeProjectId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
329
    {
330
        // Mock 'OptimizelyApiClient' object to avoid real API calls
331
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
332
                            ->disableOriginalConstructor()
333
                            ->getMock();
334
        
335
        $projectsService = new Projects($optimizelyApiClientMock);
336
        
337
        $project = new Project();
338
        
339
        $result = $projectsService->update(-1000, $project);
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
340
    }
341
    
342
    /**
343
     * @expectedException Exception
344
     */
345 View Code Duplication
    public function testUpdate_InvalidProject()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
346
    {
347
        // Mock 'OptimizelyApiClient' object to avoid real API calls
348
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
349
                            ->disableOriginalConstructor()
350
                            ->getMock();
351
        
352
        $projectsService = new Projects($optimizelyApiClientMock);
353
        
354
        $result = $projectsService->update(1000, 1);
0 ignored issues
show
Documentation introduced by
1 is of type integer, but the function expects a object<WebMarketingROI\O...HP\Resource\v2\Project>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
355
    }
356
    
357
    public function testIntegration()
358
    {
359
        if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) 
360
            $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set');
361
        
362
        $credentials = $this->loadCredentialsFromFile();
363
        
364
        $optimizelyClient = new OptimizelyApiClient($credentials, 'v2');
0 ignored issues
show
Bug introduced by
It seems like $credentials defined by $this->loadCredentialsFromFile() on line 362 can also be of type null; however, WebMarketingROI\Optimize...piClient::__construct() does only seem to accept array, maybe add an additional type check?

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:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
365
        $this->assertTrue($optimizelyClient!=null);
366
        
367
        $curDate = date('Y-m-d H:i:s');
368
        /*// Create new project        
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
369
        $newProject = new Project(array(
370
            "name" => "Test Project $curDate",
371
            "account_id" => 12345,
372
            "confidence_threshold" => 0.9,
373
            "platform" => "web",
374
            "status" => "active",
375
            "web_snippet" => array(
376
              "enable_force_variation" => false,
377
              "exclude_disabled_experiments" => false,
378
              "exclude_names" => true,
379
              "include_jquery" => true,
380
              "ip_anonymization" => false,
381
              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
382
              "library" => "jquery-1.11.3-trim",
383
              "project_javascript" => "alert(\"Active Experiment\")"
384
            )
385
        ));
386
        
387
        $result = $optimizelyClient->projects()->create($newProject);
388
        
389
        $this->assertEquals(200, $result->getHttpCode());        
390
        $this->assertTrue($result->getRateLimit()>0);
391
        $this->assertTrue($result->getRateLimitRemaining()>0);
392
        $this->assertTrue($result->getRateLimitReset()>0);
393
        
394
        $createdProject = $result->getPayload();
395
        
396
        $this->assertEquals("Test Project $curDate", $createdProject->getName());*/
397
        
398
        // List all existing projects and try to find the created project
399
        try {
400
            $projectFound = false;
401
            $projectId = null;
402
            $page = 1;
403
            for (;;) {            
404
                $result = $optimizelyClient->projects()->listAll($page);
0 ignored issues
show
Documentation Bug introduced by
The method projects does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
405
406
                print_r($optimizelyClient->getDiagnosticsInfo());
407
408
                $projects = $result->getPayload();
409
410
                foreach ($projects as $project) {
411
                    if ($project->getName()=="Test Project $curDate") {
412
                        $projectId = $project->getId();
413
                        $found = true;
0 ignored issues
show
Unused Code introduced by
$found is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
414
                        break;
415
                    }
416
                }
417
418
                if ($result->getNextPage()==null)
419
                    break;
420
421
                $page ++;
422
            }
423
        }
424
        catch (Exception $e) {
425
            print_r($optimizelyClient->getDiagnosticsInfo());
426
            // Handle error.
427
            $code = $e->getCode();
428
            $httpCode = $e->getHttpCode();
429
            $message = $e->getMessage();
430
            $uuid = $e->getUuid();
431
            echo "Exception caught: $message (code=$code http_code=$httpCode uuid=$uuid)\n";
432
        }
433
        
434
        $this->assertTrue($projectFound);
435
        
436
        // Try a non-existing project by ID - assume failure
437
        try {
438
            $result = $optimizelyClient->projects()->get(12345678);        
0 ignored issues
show
Documentation Bug introduced by
The method projects does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

Loading history...
439
        } 
440
        catch(Exception $e) {
441
            $this->assertEquals(Exception::CODE_API_ERROR, $e->getCode());
442
            $this->assertEquals(400, $e->getHttpCode());
443
            $this->assertTrue(strlen($e->getUuid())!=0);
444
            $this->assertTrue($e->getRateLimit()>0);
445
            $this->assertTrue($e->getRateLimitRemaining()>0);
446
            $this->assertTrue($e->getRateLimitReset()>0);
447
        }
448
        
449
        // Retrieve existing project by ID        
450
        $result = $optimizelyClient->projects()->get($projectId);        
0 ignored issues
show
Documentation Bug introduced by
The method projects does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
451
        $project = $result->getPayload();
452
        
453
        $this->assertEquals("Test Project $curDate", $project->getName());
454
        
455
        // Make project archived
456
        
457
        $project->setStatus('archived');
458
        $result = $optimizelyClient->projects()->update($projectId, $project);
0 ignored issues
show
Documentation Bug introduced by
The method projects does not exist on object<WebMarketingROI\O...HP\OptimizelyApiClient>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
459
        $updatedProject = $result->getPayload();
460
        
461
        $this->assertEquals('archived', $updatedProject->getStatus());
462
    }
463
}
464
465
466