| @@ 724-758 (lines=35) @@ | ||
| 721 | * @group ref |
|
| 722 | * @return void |
|
| 723 | */ |
|
| 724 | public function testPatchAddComplexObjectToSpecificIndexInArray() |
|
| 725 | { |
|
| 726 | // Load fixtures |
|
| 727 | $this->loadFixtures( |
|
| 728 | ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'], |
|
| 729 | null, |
|
| 730 | 'doctrine_mongodb' |
|
| 731 | ); |
|
| 732 | ||
| 733 | // Apply PATCH request, add new element |
|
| 734 | $client = static::createRestClient(); |
|
| 735 | $newApp = ['ref' => 'http://localhost/core/app/admin']; |
|
| 736 | $patchJson = json_encode( |
|
| 737 | [ |
|
| 738 | [ |
|
| 739 | 'op' => 'add', |
|
| 740 | 'path' => '/nestedApps/0', |
|
| 741 | 'value' => $newApp |
|
| 742 | ] |
|
| 743 | ] |
|
| 744 | ); |
|
| 745 | $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson); |
|
| 746 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
| 747 | ||
| 748 | // Check patched result |
|
| 749 | $client = static::createRestClient(); |
|
| 750 | $client->request('GET', '/hans/showcase/500'); |
|
| 751 | ||
| 752 | $result = $client->getResults(); |
|
| 753 | $this->assertEquals(3, count($result->nestedApps)); |
|
| 754 | $this->assertEquals( |
|
| 755 | 'http://localhost/core/app/admin', |
|
| 756 | $result->nestedApps[0]->{'$ref'} |
|
| 757 | ); |
|
| 758 | } |
|
| 759 | ||
| 760 | /** |
|
| 761 | * Test PATCH: add complex object App to array |
|
| @@ 766-800 (lines=35) @@ | ||
| 763 | * @group ref |
|
| 764 | * @return void |
|
| 765 | */ |
|
| 766 | public function testPatchAddComplexObjectToTheEndOfArray() |
|
| 767 | { |
|
| 768 | // Load fixtures |
|
| 769 | $this->loadFixtures( |
|
| 770 | ['GravitonDyn\ShowCaseBundle\DataFixtures\MongoDB\LoadShowCaseData'], |
|
| 771 | null, |
|
| 772 | 'doctrine_mongodb' |
|
| 773 | ); |
|
| 774 | ||
| 775 | // Apply PATCH request, add new element |
|
| 776 | $client = static::createRestClient(); |
|
| 777 | $newApp = ['ref' => 'http://localhost/core/app/test']; |
|
| 778 | $patchJson = json_encode( |
|
| 779 | [ |
|
| 780 | [ |
|
| 781 | 'op' => 'add', |
|
| 782 | 'path' => '/nestedApps/-', |
|
| 783 | 'value' => $newApp |
|
| 784 | ] |
|
| 785 | ] |
|
| 786 | ); |
|
| 787 | $client->request('PATCH', '/hans/showcase/500', array(), array(), array(), $patchJson); |
|
| 788 | $this->assertEquals(200, $client->getResponse()->getStatusCode()); |
|
| 789 | ||
| 790 | // Check patched result |
|
| 791 | $client = static::createRestClient(); |
|
| 792 | $client->request('GET', '/hans/showcase/500'); |
|
| 793 | ||
| 794 | $result = $client->getResults(); |
|
| 795 | $this->assertEquals(3, count($result->nestedApps)); |
|
| 796 | $this->assertEquals( |
|
| 797 | 'http://localhost/core/app/test', |
|
| 798 | $result->nestedApps[2]->{'$ref'} |
|
| 799 | ); |
|
| 800 | } |
|
| 801 | ||
| 802 | /** |
|
| 803 | * Test PATCH: test operation to undefined index |
|