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