Code Duplication    Length = 30-35 lines in 4 locations

src/Graviton/CoreBundle/Tests/Controller/ShowcaseControllerTest.php 4 locations

@@ 412-444 (lines=33) @@
409
     *
410
     * @return void
411
     */
412
    public function testPatchDeepNestedProperty()
413
    {
414
        // Load fixtures
415
        $this->loadFixtures(
416
            ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'],
417
            null,
418
            'doctrine_mongodb'
419
        );
420
421
        // Apply PATCH request
422
        $client = static::createRestClient();
423
        $patchJson = json_encode(
424
            [
425
                [
426
                    'op' => 'replace',
427
                    'path' => '/unstructuredObject/hashField/anotherField',
428
                    'value' => 'changed nested hash field with patch'
429
                ]
430
            ]
431
        );
432
        $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson);
433
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
434
435
        // Get changed showcase
436
        $client = static::createRestClient();
437
        $client->request('GET', '/hans/showcase/500');
438
439
        $result = $client->getResults();
440
        $this->assertEquals(
441
            'changed nested hash field with patch',
442
            $result->unstructuredObject->hashField->anotherField
443
        );
444
    }
445
446
    /**
447
     * Test success PATCH method - response headers contains link to resource
@@ 513-545 (lines=33) @@
510
     *
511
     * @return void
512
     */
513
    public function testPatchAddPropertyToFreeObject()
514
    {
515
        // Load fixtures
516
        $this->loadFixtures(
517
            ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'],
518
            null,
519
            'doctrine_mongodb'
520
        );
521
522
        // Apply PATCH request
523
        $client = static::createRestClient();
524
        $patchJson = json_encode(
525
            [
526
                [
527
                    'op' => 'add',
528
                    'path' => '/unstructuredObject/hashField/newAddedField',
529
                    'value' => 'new field value'
530
                ]
531
            ]
532
        );
533
        $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson);
534
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
535
536
        // Get changed showcase
537
        $client = static::createRestClient();
538
        $client->request('GET', '/hans/showcase/500');
539
540
        $result = $client->getResults();
541
        $this->assertEquals(
542
            'new field value',
543
            $result->unstructuredObject->hashField->newAddedField
544
        );
545
    }
546
547
    /**
548
     * Test PATCH for $ref attribute
@@ 553-587 (lines=35) @@
550
     * @return void
551
     * @incomplete
552
     */
553
    public function testApplyPatchForRefAttribute()
554
    {
555
        // Load fixtures
556
        $this->loadFixtures(
557
            [
558
                'GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'
559
            ],
560
            null,
561
            'doctrine_mongodb'
562
        );
563
564
        // Apply PATCH request
565
        $client = static::createRestClient();
566
        $patchJson = json_encode(
567
            [
568
                [
569
                    'op' => 'replace',
570
                    'path' => '/nestedApps/0/$ref',
571
                    'value' => 'http://localhost/core/app/admin'
572
                ]
573
            ]
574
        );
575
        $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson);
576
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
577
578
        // Check patched result
579
        $client = static::createRestClient();
580
        $client->request('GET', '/hans/showcase/500');
581
582
        $result = $client->getResults();
583
        $this->assertEquals(
584
            'http://localhost/core/app/admin',
585
            $result->nestedApps[0]->{'$ref'}
586
        );
587
    }
588
589
    /**
590
     * Test PATCH: apply patch which results to invalid Showcase schema
@@ 629-658 (lines=30) @@
626
     *
627
     * @return void
628
     */
629
    public function testRemoveFromArrayPatch()
630
    {
631
        // Load fixtures
632
        $this->loadFixtures(
633
            ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'],
634
            null,
635
            'doctrine_mongodb'
636
        );
637
638
        // Apply PATCH request, remove nested app, initially there are 2 apps
639
        $client = static::createRestClient();
640
        $patchJson = json_encode(
641
            [
642
                [
643
                    'op' => 'remove',
644
                    'path' => '/nestedApps/0'
645
                ]
646
            ]
647
        );
648
        $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson);
649
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
650
651
        // Check patched result
652
        $client = static::createRestClient();
653
        $client->request('GET', '/hans/showcase/500');
654
655
        $result = $client->getResults();
656
        $this->assertEquals(1, count($result->nestedApps));
657
        $this->assertEquals('http://localhost/core/app/admin', $result->nestedApps[0]->{'$ref'});
658
    }
659
660
    /**
661
     * Test PATCH: add new element to array