Code Duplication    Length = 45-45 lines in 2 locations

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 2 locations

@@ 4030-4074 (lines=45) @@
4027
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4028
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4029
     */
4030
    public function testUpdateContentMetadataInTransactionWithRollback()
4031
    {
4032
        $repository = $this->getRepository();
4033
4034
        $contentId = $this->generateId('object', 12);
4035
        /* BEGIN: Use Case */
4036
        // $contentId is the ID of the "Administrator users" user group
4037
4038
        // Get the content service
4039
        $contentService = $repository->getContentService();
4040
4041
        // Load a ContentInfo object
4042
        $contentInfo = $contentService->loadContentInfo($contentId);
4043
4044
        // Store remoteId for later testing
4045
        $remoteId = $contentInfo->remoteId;
4046
4047
        // Start a transaction
4048
        $repository->beginTransaction();
4049
4050
        try {
4051
            // Get metadata update struct and change remoteId
4052
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4053
            $metadataUpdate->remoteId = md5(microtime(true));
4054
4055
            // Update the metadata of the published content object
4056
            $contentService->updateContentMetadata(
4057
                $contentInfo,
4058
                $metadataUpdate
4059
            );
4060
        } catch (Exception $e) {
4061
            // Cleanup hanging transaction on error
4062
            $repository->rollback();
4063
            throw $e;
4064
        }
4065
4066
        // Rollback all changes.
4067
        $repository->rollback();
4068
4069
        // Load current remoteId
4070
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4071
        /* END: Use Case */
4072
4073
        $this->assertEquals($remoteId, $remoteIdReloaded);
4074
    }
4075
4076
    /**
4077
     * Test for the updateContentMetadata() method.
@@ 4083-4127 (lines=45) @@
4080
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4081
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4082
     */
4083
    public function testUpdateContentMetadataInTransactionWithCommit()
4084
    {
4085
        $repository = $this->getRepository();
4086
4087
        $contentId = $this->generateId('object', 12);
4088
        /* BEGIN: Use Case */
4089
        // $contentId is the ID of the "Administrator users" user group
4090
4091
        // Get the content service
4092
        $contentService = $repository->getContentService();
4093
4094
        // Load a ContentInfo object
4095
        $contentInfo = $contentService->loadContentInfo($contentId);
4096
4097
        // Store remoteId for later testing
4098
        $remoteId = $contentInfo->remoteId;
4099
4100
        // Start a transaction
4101
        $repository->beginTransaction();
4102
4103
        try {
4104
            // Get metadata update struct and change remoteId
4105
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4106
            $metadataUpdate->remoteId = md5(microtime(true));
4107
4108
            // Update the metadata of the published content object
4109
            $contentService->updateContentMetadata(
4110
                $contentInfo,
4111
                $metadataUpdate
4112
            );
4113
4114
            // Commit all changes.
4115
            $repository->commit();
4116
        } catch (Exception $e) {
4117
            // Cleanup hanging transaction on error
4118
            $repository->rollback();
4119
            throw $e;
4120
        }
4121
4122
        // Load current remoteId
4123
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4124
        /* END: Use Case */
4125
4126
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4127
    }
4128
4129
    /**
4130
     * Test for the deleteVersion() method.