Code Duplication    Length = 42-42 lines in 2 locations

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

@@ 4349-4390 (lines=42) @@
4346
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4347
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4348
     */
4349
    public function testUpdateContentMetadataInTransactionWithRollback()
4350
    {
4351
        $repository = $this->getRepository();
4352
4353
        $contentId = $this->generateId('object', 12);
4354
        /* BEGIN: Use Case */
4355
        // $contentId is the ID of the "Administrator users" user group
4356
4357
        // Load a ContentInfo object
4358
        $contentInfo = $this->contentService->loadContentInfo($contentId);
4359
4360
        // Store remoteId for later testing
4361
        $remoteId = $contentInfo->remoteId;
4362
4363
        // Start a transaction
4364
        $repository->beginTransaction();
4365
4366
        try {
4367
            // Get metadata update struct and change remoteId
4368
            $metadataUpdate = $this->contentService->newContentMetadataUpdateStruct();
4369
            $metadataUpdate->remoteId = md5(microtime(true));
4370
4371
            // Update the metadata of the published content object
4372
            $this->contentService->updateContentMetadata(
4373
                $contentInfo,
4374
                $metadataUpdate
4375
            );
4376
        } catch (Exception $e) {
4377
            // Cleanup hanging transaction on error
4378
            $repository->rollback();
4379
            throw $e;
4380
        }
4381
4382
        // Rollback all changes.
4383
        $repository->rollback();
4384
4385
        // Load current remoteId
4386
        $remoteIdReloaded = $this->contentService->loadContentInfo($contentId)->remoteId;
4387
        /* END: Use Case */
4388
4389
        $this->assertEquals($remoteId, $remoteIdReloaded);
4390
    }
4391
4392
    /**
4393
     * Test for the updateContentMetadata() method.
@@ 4399-4440 (lines=42) @@
4396
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4397
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4398
     */
4399
    public function testUpdateContentMetadataInTransactionWithCommit()
4400
    {
4401
        $repository = $this->getRepository();
4402
4403
        $contentId = $this->generateId('object', 12);
4404
        /* BEGIN: Use Case */
4405
        // $contentId is the ID of the "Administrator users" user group
4406
4407
        // Load a ContentInfo object
4408
        $contentInfo = $this->contentService->loadContentInfo($contentId);
4409
4410
        // Store remoteId for later testing
4411
        $remoteId = $contentInfo->remoteId;
4412
4413
        // Start a transaction
4414
        $repository->beginTransaction();
4415
4416
        try {
4417
            // Get metadata update struct and change remoteId
4418
            $metadataUpdate = $this->contentService->newContentMetadataUpdateStruct();
4419
            $metadataUpdate->remoteId = md5(microtime(true));
4420
4421
            // Update the metadata of the published content object
4422
            $this->contentService->updateContentMetadata(
4423
                $contentInfo,
4424
                $metadataUpdate
4425
            );
4426
4427
            // Commit all changes.
4428
            $repository->commit();
4429
        } catch (Exception $e) {
4430
            // Cleanup hanging transaction on error
4431
            $repository->rollback();
4432
            throw $e;
4433
        }
4434
4435
        // Load current remoteId
4436
        $remoteIdReloaded = $this->contentService->loadContentInfo($contentId)->remoteId;
4437
        /* END: Use Case */
4438
4439
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4440
    }
4441
4442
    /**
4443
     * Test for the deleteVersion() method.