Code Duplication    Length = 31-31 lines in 2 locations

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

@@ 1015-1045 (lines=31) @@
1012
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1013
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
1014
     */
1015
    public function testCreateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
1016
    {
1017
        $repository = $this->getRepository();
1018
1019
        $editorsGroupId = $this->generateId('group', 13);
1020
        /* BEGIN: Use Case */
1021
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
1022
        // Publish demo installation
1023
1024
        $userService = $repository->getUserService();
1025
1026
        // Instantiate a create struct with mandatory properties
1027
        $userCreate = $userService->newUserCreateStruct(
1028
            'user',
1029
            '[email protected]',
1030
            'secret',
1031
            'eng-US'
1032
        );
1033
1034
        // An object of stdClass is not a valid value for the field first_name
1035
        $userCreate->setField('first_name', new \stdClass());
1036
        $userCreate->setField('last_name', 'User');
1037
1038
        // Load parent group for the user
1039
        $group = $userService->loadUserGroup($editorsGroupId);
1040
1041
        // This call will fail with an "InvalidArgumentException", because the
1042
        // value for the firled "first_name" is not accepted by the field type.
1043
        $userService->createUser($userCreate, array($group));
1044
        /* END: Use Case */
1045
    }
1046
1047
    /**
1048
     * Test for the createUser() method.
@@ 1055-1085 (lines=31) @@
1052
     * @expectedExceptionMessage Argument 'userCreateStruct' is invalid: User with provided login already exists
1053
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
1054
     */
1055
    public function testCreateUserThrowsInvalidArgumentException()
1056
    {
1057
        $repository = $this->getRepository();
1058
1059
        $editorsGroupId = $this->generateId('group', 13);
1060
        /* BEGIN: Use Case */
1061
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
1062
        // Publish demo installation
1063
1064
        $userService = $repository->getUserService();
1065
1066
        // Instantiate a create struct with mandatory properties
1067
        $userCreate = $userService->newUserCreateStruct(
1068
            // admin is an existing login
1069
            'admin',
1070
            '[email protected]',
1071
            'secret',
1072
            'eng-US'
1073
        );
1074
1075
        $userCreate->setField('first_name', 'Example');
1076
        $userCreate->setField('last_name', 'User');
1077
1078
        // Load parent group for the user
1079
        $group = $userService->loadUserGroup($editorsGroupId);
1080
1081
        // This call will fail with a "InvalidArgumentException", because the
1082
        // user with "admin" login already exists.
1083
        $userService->createUser($userCreate, array($group));
1084
        /* END: Use Case */
1085
    }
1086
1087
    /**
1088
     * Test for the createUser() method.