Completed
Push — master ( d8826f...ec36d3 )
by Oleg
02:45
created

ProjectsTest::testUpdate_NotIntegerProjectId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ProjectsTest::testUpdate_InvalidProject() 11 11 1
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 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...
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
    public function testCreate()
148
    {
149
        // Mock 'OptimizelyApiClient' object to avoid real API calls
150
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
151
                            ->disableOriginalConstructor()
152
                            ->getMock();
153
154
        $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...
155
        
156
        $result = new Result(array(
157
                            "name" => "Test Project",
158
                            "account_id" => 12345,
159
                            "confidence_threshold" => 0.9,
160
                            "dcp_service_id" => 121234,
161
                            "platform" => "web",
162
                            "status" => "active",
163
                            "web_snippet" => array(
164
                              "enable_force_variation" => false,
165
                              "exclude_disabled_experiments" => false,
166
                              "exclude_names" => true,
167
                              "include_jquery" => true,
168
                              "ip_anonymization" => false,
169
                              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
170
                              "library" => "jquery-1.11.3-trim",
171
                              "project_javascript" => "alert(\"Active Experiment\")",
172
                              "code_revision" => 0,
173
                              "js_file_size" => 63495
174
                            ),
175
                            "created" => "2016-10-17T07:04:59.991Z",
176
                            "id" => 1000,
177
                            "is_classic" => true,
178
                            "last_modified" => "2016-10-17T07:04:59.991Z",
179
                            "socket_token" => "AABBCCDD~123456789"                   
180
                        ), 201);
181
        $optimizelyApiClientMock->method('sendApiRequest')
182
                    ->willReturn($result);
183
        
184
        $projectsService = new Projects($optimizelyApiClientMock);
185
        
186
        $project = new Project(array(
187
            "name" => "Test Project",
188
            "account_id" => 12345,
189
            "confidence_threshold" => 0.9,
190
            "dcp_service_id" => 121234,
191
            "platform" => "web",
192
            "status" => "active",
193
            "web_snippet" => array(
194
              "enable_force_variation" => false,
195
              "exclude_disabled_experiments" => false,
196
              "exclude_names" => true,
197
              "include_jquery" => true,
198
              "ip_anonymization" => false,
199
              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
200
              "library" => "jquery-1.11.3-trim",
201
              "project_javascript" => "alert(\"Active Experiment\")"
202
            )
203
        ));
204
        
205
        $result = $projectsService->create($project);
206
        $createdProject = $result->getPayload();
207
        
208
        $this->assertTrue($createdProject instanceOf Project);
209
        $this->assertTrue($createdProject->getName()=='Test Project');        
210
        $this->assertTrue($createdProject->getAccountId()==12345);        
211
    }
212
    
213
    /**
214
     * @expectedException Exception
215
     */
216 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...
217
    {
218
        // Mock 'OptimizelyApiClient' object to avoid real API calls
219
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
220
                            ->disableOriginalConstructor()
221
                            ->getMock();
222
        
223
        $projectsService = new Projects($optimizelyApiClientMock);
224
        
225
        $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...
226
    }
227
    
228
    public function testUpdate()
229
    {
230
        // Mock 'OptimizelyApiClient' object to avoid real API calls
231
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
232
                            ->disableOriginalConstructor()
233
                            ->getMock();
234
235
        $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...
236
        
237
        $result = new Result(array(
238
                            "name" => "Test Project",
239
                            "account_id" => 12345,
240
                            "confidence_threshold" => 0.9,
241
                            "dcp_service_id" => 121234,
242
                            "platform" => "web",
243
                            "status" => "active",
244
                            "web_snippet" => array(
245
                              "enable_force_variation" => false,
246
                              "exclude_disabled_experiments" => false,
247
                              "exclude_names" => true,
248
                              "include_jquery" => true,
249
                              "ip_anonymization" => false,
250
                              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
251
                              "library" => "jquery-1.11.3-trim",
252
                              "project_javascript" => "alert(\"Active Experiment\")",
253
                              "code_revision" => 0,
254
                              "js_file_size" => 63495
255
                            ),
256
                            "created" => "2016-10-17T07:04:59.999Z",
257
                            "id" => 1000,
258
                            "is_classic" => true,
259
                            "last_modified" => "2016-10-17T07:04:59.999Z",
260
                            "socket_token" => "AABBCCDD~123456789"
261
                        ), 200);
262
        
263
        $optimizelyApiClientMock->method('sendApiRequest')
264
                    ->willReturn($result);
265
        
266
        $projectsService = new Projects($optimizelyApiClientMock);
267
        
268
        $project = new Project(array(
269
            "confidence_threshold" => 0.9,
270
            "dcp_service_id" => 121234,
271
            "name" => "Test Project",
272
            "status" => "active",
273
            "web_snippet" => array(
274
              "enable_force_variation" => false,
275
              "exclude_disabled_experiments" => false,
276
              "exclude_names" => true,
277
              "include_jquery" => true,
278
              "ip_anonymization" => false,
279
              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
280
              "library" => "jquery-1.11.3-trim",
281
              "project_javascript" => "alert(\"Active Experiment\")"
282
            )
283
        ));
284
        
285
        $result = $projectsService->update(121234, $project);
286
        $updatedProject = $result->getPayload();
287
        
288
        $this->assertTrue($updatedProject instanceOf Project);
289
        $this->assertTrue($updatedProject->getName()=='Test Project');        
290
        $this->assertTrue($updatedProject->getAccountId()==12345);        
291
    }
292
    
293
    /**
294
     * @expectedException Exception
295
     */
296 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...
297
    {
298
        // Mock 'OptimizelyApiClient' object to avoid real API calls
299
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
300
                            ->disableOriginalConstructor()
301
                            ->getMock();
302
        
303
        $projectsService = new Projects($optimizelyApiClientMock);
304
        
305
        $project = new Project();
306
        
307
        $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...
308
    }
309
    
310
    /**
311
     * @expectedException Exception
312
     */
313 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...
314
    {
315
        // Mock 'OptimizelyApiClient' object to avoid real API calls
316
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
317
                            ->disableOriginalConstructor()
318
                            ->getMock();
319
        
320
        $projectsService = new Projects($optimizelyApiClientMock);
321
        
322
        $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...
323
    }
324
    
325
    public function testIntegration()
326
    {
327
        if (!getenv('OPTIMIZELY_PHP_TEST_INTEGRATION')) 
328
            $this->markTestSkipped('OPTIMIZELY_PHP_TEST_INTEGRATION env var is not set');
329
        
330
        $credentials = $this->loadCredentialsFromFile();
331
        
332
        $optimizelyClient = new OptimizelyApiClient($credentials, 'v2');
0 ignored issues
show
Bug introduced by
It seems like $credentials defined by $this->loadCredentialsFromFile() on line 330 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...
333
        $this->assertTrue($optimizelyClient!=null);
334
                
335
        // Create new project        
336
        $curDate = date('Y-m-d H:i:s');
337
        $newProject = new Project(array(
338
            "name" => "Test Project $curDate",
339
            "account_id" => 12345,
340
            "confidence_threshold" => 0.9,
341
            "platform" => "web",
342
            "status" => "active",
343
            "web_snippet" => array(
344
              "enable_force_variation" => false,
345
              "exclude_disabled_experiments" => false,
346
              "exclude_names" => true,
347
              "include_jquery" => true,
348
              "ip_anonymization" => false,
349
              "ip_filter" => "^206\\.23\\.100\\.([5-9][0-9]|1([0-4][0-9]|50))$",
350
              "library" => "jquery-1.11.3-trim",
351
              "project_javascript" => "alert(\"Active Experiment\")"
352
            )
353
        ));
354
        
355
        $result = $optimizelyClient->projects()->create($newProject);
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...
356
        
357
        $this->assertEquals(200, $result->getHttpCode());        
358
        $this->assertTrue($result->getRateLimit()>0);
359
        $this->assertTrue($result->getRateLimitRemaining()>0);
360
        $this->assertTrue($result->getRateLimitReset()>0);
361
        
362
        $createdProject = $result->getPayload();
363
        
364
        print_r($optimizelyClient->getDiagnosticsInfo());
365
        
366
        $this->assertEquals("Test Project $curDate", $createdProject->getName());
367
        
368
        // List all existing projects and try to find the created project
369
        $projectFound = false;
370
        $projectId = null;            
371
        try {
372
            $page = 1;
373
            for (;;) {            
374
                echo " = Page $page\n";
375
                $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...
376
377
                print_r($optimizelyClient->getDiagnosticsInfo());
378
379
                $projects = $result->getPayload();
380
381
                foreach ($projects as $project) {
382
                    echo "Name: " . $project->getName() . "\n";
383
                    if ($project->getName()=="Test Project $curDate") {
384
                        $projectId = $project->getId();
385
                        $projectFound = true;
386
                        break;
387
                    }
388
                }
389
390
                if ($result->getNextPage()==null)
391
                    break;
392
393
                $page ++;
394
            }
395
        }
396
        catch (Exception $e) {
397
            // Handle error.
398
            $code = $e->getCode();
399
            $httpCode = $e->getHttpCode();
400
            $message = $e->getMessage();
401
            $uuid = $e->getUuid();
402
            echo "Exception caught: $message (code=$code http_code=$httpCode uuid=$uuid)\n";
403
        }
404
        
405
        $this->assertTrue($projectFound);
406
        
407
        // Try a non-existing project by ID - assume failure
408
        try {
409
            $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...
410
        } 
411
        catch(Exception $e) {
412
            //print_r($optimizelyClient->getDiagnosticsInfo());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
413
            $this->assertEquals(Exception::CODE_API_ERROR, $e->getCode());
414
            $this->assertEquals('not_found', $e->getHttpCode());
415
            $this->assertTrue(strlen($e->getUuid())!=0);
416
            $this->assertTrue($e->getRateLimit()>0);
417
            $this->assertTrue($e->getRateLimitRemaining()>0);
418
            $this->assertTrue($e->getRateLimitReset()>0);
419
        }
420
        
421
        // Retrieve existing project by ID        
422
        $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...
423
        $project = $result->getPayload();
424
        
425
        $this->assertEquals("Test Project $curDate", $project->getName());
426
        
427
        // Make project archived
428
        
429
        $project->setStatus('archived');
430
        $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...
431
        $updatedProject = $result->getPayload();
432
        
433
        $this->assertEquals('archived', $updatedProject->getStatus());
434
    }
435
}
436
437
438