Code Duplication    Length = 28-31 lines in 2 locations

eZ/Publish/API/Repository/Tests/UserServiceTest.php 1 location

@@ 1066-1093 (lines=28) @@
1063
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testNewUserCreateStruct
1064
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContent
1065
     */
1066
    public function testCreateUserInTransactionWithRollback()
1067
    {
1068
        $repository = $this->getRepository();
1069
        $userService = $repository->getUserService();
1070
1071
        /* BEGIN: Use Case */
1072
        $repository->beginTransaction();
1073
1074
        try {
1075
            $user = $this->createUserVersion1();
1076
        } catch (Exception $e) {
1077
            // Cleanup hanging transaction on error
1078
            $repository->rollback();
1079
            throw $e;
1080
        }
1081
1082
        $repository->rollback();
1083
1084
        try {
1085
            // Throws exception since creation of user was rolled back
1086
            $loadedUser = $userService->loadUser($user->id);
1087
        } catch (NotFoundException $e) {
1088
            return;
1089
        }
1090
        /* END: Use Case */
1091
1092
        $this->fail('User object still exists after rollback.');
1093
    }
1094
1095
    /**
1096
     * Test creating a user throwing NotFoundException.

eZ/Publish/API/Repository/Tests/ContentServiceTest.php 1 location

@@ 4117-4147 (lines=31) @@
4114
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testCreateContentWithLocationCreateParameterDoesNotCreateLocationImmediately
4115
     * @depends eZ\Publish\API\Repository\Tests\ContentServiceTest::testLoadContentThrowsNotFoundException
4116
     */
4117
    public function testCreateContentWithLocationCreateParameterInTransactionWithRollback()
4118
    {
4119
        $repository = $this->getRepository();
4120
4121
        /* BEGIN: Use Case */
4122
        // Start a transaction
4123
        $repository->beginTransaction();
4124
4125
        try {
4126
            $draft = $this->createContentDraftVersion1();
4127
        } catch (Exception $e) {
4128
            // Cleanup hanging transaction on error
4129
            $repository->rollback();
4130
            throw $e;
4131
        }
4132
4133
        $contentId = $draft->id;
4134
4135
        // Roleback the transaction
4136
        $repository->rollback();
4137
4138
        try {
4139
            // This call will fail with a "NotFoundException"
4140
            $this->contentService->loadContent($contentId);
4141
        } catch (NotFoundException $e) {
4142
            return;
4143
        }
4144
        /* END: Use Case */
4145
4146
        $this->fail('Can still load content object after rollback.');
4147
    }
4148
4149
    /**
4150
     * Test for the createContent() method.