Code Duplication    Length = 45-45 lines in 2 locations

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

@@ 4565-4609 (lines=45) @@
4562
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4563
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4564
     */
4565
    public function testUpdateContentMetadataInTransactionWithRollback()
4566
    {
4567
        $repository = $this->getRepository();
4568
4569
        $contentId = $this->generateId('object', 12);
4570
        /* BEGIN: Use Case */
4571
        // $contentId is the ID of the "Administrator users" user group
4572
4573
        // Get the content service
4574
        $contentService = $repository->getContentService();
4575
4576
        // Load a ContentInfo object
4577
        $contentInfo = $contentService->loadContentInfo($contentId);
4578
4579
        // Store remoteId for later testing
4580
        $remoteId = $contentInfo->remoteId;
4581
4582
        // Start a transaction
4583
        $repository->beginTransaction();
4584
4585
        try {
4586
            // Get metadata update struct and change remoteId
4587
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4588
            $metadataUpdate->remoteId = md5(microtime(true));
4589
4590
            // Update the metadata of the published content object
4591
            $contentService->updateContentMetadata(
4592
                $contentInfo,
4593
                $metadataUpdate
4594
            );
4595
        } catch (Exception $e) {
4596
            // Cleanup hanging transaction on error
4597
            $repository->rollback();
4598
            throw $e;
4599
        }
4600
4601
        // Rollback all changes.
4602
        $repository->rollback();
4603
4604
        // Load current remoteId
4605
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4606
        /* END: Use Case */
4607
4608
        $this->assertEquals($remoteId, $remoteIdReloaded);
4609
    }
4610
4611
    /**
4612
     * Test for the updateContentMetadata() method.
@@ 4618-4662 (lines=45) @@
4615
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testUpdateContentMetadata
4616
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentInfo
4617
     */
4618
    public function testUpdateContentMetadataInTransactionWithCommit()
4619
    {
4620
        $repository = $this->getRepository();
4621
4622
        $contentId = $this->generateId('object', 12);
4623
        /* BEGIN: Use Case */
4624
        // $contentId is the ID of the "Administrator users" user group
4625
4626
        // Get the content service
4627
        $contentService = $repository->getContentService();
4628
4629
        // Load a ContentInfo object
4630
        $contentInfo = $contentService->loadContentInfo($contentId);
4631
4632
        // Store remoteId for later testing
4633
        $remoteId = $contentInfo->remoteId;
4634
4635
        // Start a transaction
4636
        $repository->beginTransaction();
4637
4638
        try {
4639
            // Get metadata update struct and change remoteId
4640
            $metadataUpdate = $contentService->newContentMetadataUpdateStruct();
4641
            $metadataUpdate->remoteId = md5(microtime(true));
4642
4643
            // Update the metadata of the published content object
4644
            $contentService->updateContentMetadata(
4645
                $contentInfo,
4646
                $metadataUpdate
4647
            );
4648
4649
            // Commit all changes.
4650
            $repository->commit();
4651
        } catch (Exception $e) {
4652
            // Cleanup hanging transaction on error
4653
            $repository->rollback();
4654
            throw $e;
4655
        }
4656
4657
        // Load current remoteId
4658
        $remoteIdReloaded = $contentService->loadContentInfo($contentId)->remoteId;
4659
        /* END: Use Case */
4660
4661
        $this->assertNotEquals($remoteId, $remoteIdReloaded);
4662
    }
4663
4664
    /**
4665
     * Test for the deleteVersion() method.