Code Duplication    Length = 101-101 lines in 2 locations

tests/OptimizelyPHPTest/Service/v2/CampaignsTest.php 2 locations

@@ 242-342 (lines=101) @@
239
        $this->assertTrue($campaignResults->getStartTime()=="2016-10-18T03:27:04.148Z");        
240
    }
241
    
242
    public function testCreate()
243
    {
244
        // Mock 'OptimizelyApiClient' object to avoid real API calls
245
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
246
                            ->disableOriginalConstructor()
247
                            ->getMock();
248
249
        $result = new Result(array(
250
                            "project_id" => 1000,
251
                            "changes" => array(
252
                              array(
253
                                "type" => "custom_code",
254
                                "allow_additional_redirect" => true, 
255
                                "async" => true,
256
                                "css_selector" => "a[href*=\"optimizely\"]",
257
                                "dependencies" => array(
258
                                  24,
259
                                  26
260
                                ),
261
                                "destination" => "https://app.optimizely.com/",
262
                                "extension_id" => 1234,
263
                                "preserve_parameters" => true,
264
                                "src" => 524,
265
                                "value" => "window.someGlobalFunction();",
266
                                "id" => "string"
267
                              )
268
                            ),
269
                            "created" => "2016-10-18T03:27:04.155Z",
270
                            "earliest" => "2016-10-18T03:27:04.155Z",
271
                            "experiment_ids" => array(
272
                              0
273
                            ),
274
                            "holdback" => 0,
275
                            "last_modified" => "2016-10-18T03:27:04.155Z",
276
                            "latest" => "2016-10-18T03:27:04.155Z",
277
                            "metrics" => array(
278
                              array(
279
                                "kind" => "string",
280
                                "id" => 0
281
                              )
282
                            ),
283
                            "name" => "Landing Page Optimization",
284
                            "page_ids" => array(
285
                              0
286
                            ),
287
                            "status" => "active",
288
                            "type" => "a/b",
289
                            "id" => 2000
290
                        ), 201);
291
        
292
        $optimizelyApiClientMock->method('sendApiRequest')
293
                    ->willReturn($result);
294
        
295
        $campaignsService = new Campaigns($optimizelyApiClientMock);
296
        
297
        $campaign = new Campaign(array(
298
                "project_id" => 1000,
299
                "changes" => array(
300
                  array(
301
                    "type" => "custom_code",
302
                    "allow_additional_redirect" => true,
303
                    "async" => true,
304
                    "css_selector" => "a[href*=\"optimizely\"]",
305
                    "dependencies" => array(
306
                      24,
307
                      26
308
                    ),
309
                    "destination" => "https://app.optimizely.com/",
310
                    "extension_id" => 1234,
311
                    "preserve_parameters" => true,
312
                    "src" => 524,
313
                    "value" => "window.someGlobalFunction();"
314
                  )
315
                ),
316
                "created" => "2016-10-18T03:27:04.067Z",
317
                "earliest" => "2016-10-18T03:27:04.067Z",
318
                "experiment_ids" => array(
319
                  0
320
                ),
321
                "holdback" => 0,
322
                "last_modified" => "2016-10-18T03:27:04.067Z",
323
                "latest" => "2016-10-18T03:27:04.067Z",
324
                "metrics" => array(
325
                  array(
326
                    "kind" => "string"
327
                  )
328
                ),
329
                "name" => "Landing Page Optimization",
330
                "page_ids" => array(
331
                  0
332
                ),
333
                "status" => "active",
334
                "type" => "a/b"
335
        ));
336
        
337
        $result = $campaignsService->create($campaign);
338
        $createdCampaign = $result->getPayload();
339
        
340
        $this->assertTrue($createdCampaign instanceOf Campaign);
341
        $this->assertTrue($createdCampaign->getName()=='Landing Page Optimization');                
342
    }
343
    
344
    public function testUpdate()
345
    {
@@ 344-444 (lines=101) @@
341
        $this->assertTrue($createdCampaign->getName()=='Landing Page Optimization');                
342
    }
343
    
344
    public function testUpdate()
345
    {
346
        // Mock 'OptimizelyApiClient' object to avoid real API calls
347
        $optimizelyApiClientMock = $this->getMockBuilder('\WebMarketingROI\OptimizelyPHP\OptimizelyApiClient')
348
                            ->disableOriginalConstructor()
349
                            ->getMock();
350
351
        $result = new Result(array(
352
                            "project_id" => 1000,
353
                            "changes" => array(
354
                              array(
355
                                "type" => "custom_code",
356
                                "allow_additional_redirect" => true, 
357
                                "async" => true,
358
                                "css_selector" => "a[href*=\"optimizely\"]",
359
                                "dependencies" => array(
360
                                  24,
361
                                  26
362
                                ),
363
                                "destination" => "https://app.optimizely.com/",
364
                                "extension_id" => 1234,
365
                                "preserve_parameters" => true,
366
                                "src" => 524,
367
                                "value" => "window.someGlobalFunction();",
368
                                "id" => "string"
369
                              )
370
                            ),
371
                            "created" => "2016-10-18T03:27:04.155Z",
372
                            "earliest" => "2016-10-18T03:27:04.155Z",
373
                            "experiment_ids" => array(
374
                              0
375
                            ),
376
                            "holdback" => 0,
377
                            "last_modified" => "2016-10-18T03:27:04.155Z",
378
                            "latest" => "2016-10-18T03:27:04.155Z",
379
                            "metrics" => array(
380
                              array(
381
                                "kind" => "string",
382
                                "id" => 0
383
                              )
384
                            ),
385
                            "name" => "Landing Page Optimization",
386
                            "page_ids" => array(
387
                              0
388
                            ),
389
                            "status" => "active",
390
                            "type" => "a/b",
391
                            "id" => 2000
392
                        ), 200);
393
        
394
        $optimizelyApiClientMock->method('sendApiRequest')
395
                    ->willReturn($result);
396
        
397
        $campaignsService = new Campaigns($optimizelyApiClientMock);
398
        
399
        $campaign = new Campaign(array(
400
                "project_id" => 1000,
401
                "changes" => array(
402
                  array(
403
                    "type" => "custom_code",
404
                    "allow_additional_redirect" => true,
405
                    "async" => true,
406
                    "css_selector" => "a[href*=\"optimizely\"]",
407
                    "dependencies" => array(
408
                      24,
409
                      26
410
                    ),
411
                    "destination" => "https://app.optimizely.com/",
412
                    "extension_id" => 1234,
413
                    "preserve_parameters" => true,
414
                    "src" => 524,
415
                    "value" => "window.someGlobalFunction();"
416
                  )
417
                ),
418
                "created" => "2016-10-18T03:27:04.067Z",
419
                "earliest" => "2016-10-18T03:27:04.067Z",
420
                "experiment_ids" => array(
421
                  0
422
                ),
423
                "holdback" => 0,
424
                "last_modified" => "2016-10-18T03:27:04.067Z",
425
                "latest" => "2016-10-18T03:27:04.067Z",
426
                "metrics" => array(
427
                  array(
428
                    "kind" => "string"
429
                  )
430
                ),
431
                "name" => "Landing Page Optimization",
432
                "page_ids" => array(
433
                  0
434
                ),
435
                "status" => "active",
436
                "type" => "a/b"
437
        ));
438
        
439
        $result = $campaignsService->update(2000, $campaign);
440
        $updatedCampaign = $result->getPayload();
441
                 
442
        $this->assertTrue($updatedCampaign instanceOf Campaign);
443
        $this->assertTrue($updatedCampaign->getName()=='Landing Page Optimization');                
444
    }
445
    
446
    public function testDelete()
447
    {