Code Duplication    Length = 31-31 lines in 2 locations

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

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