Code Duplication    Length = 30-35 lines in 4 locations

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

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