Code Duplication    Length = 31-31 lines in 2 locations

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

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