Code Duplication    Length = 31-31 lines in 2 locations

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

@@ 946-976 (lines=31) @@
943
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
944
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
945
     */
946
    public function testCreateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
947
    {
948
        $repository = $this->getRepository();
949
950
        $editorsGroupId = $this->generateId('group', 13);
951
        /* BEGIN: Use Case */
952
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
953
        // Publish demo installation
954
955
        $userService = $repository->getUserService();
956
957
        // Instantiate a create struct with mandatory properties
958
        $userCreate = $userService->newUserCreateStruct(
959
            'user',
960
            '[email protected]',
961
            'secret',
962
            'eng-US'
963
        );
964
965
        // An object of stdClass is not a valid value for the field first_name
966
        $userCreate->setField('first_name', new \stdClass());
967
        $userCreate->setField('last_name', 'User');
968
969
        // Load parent group for the user
970
        $group = $userService->loadUserGroup($editorsGroupId);
971
972
        // This call will fail with an "InvalidArgumentException", because the
973
        // value for the firled "first_name" is not accepted by the field type.
974
        $userService->createUser($userCreate, array($group));
975
        /* END: Use Case */
976
    }
977
978
    /**
979
     * Test for the createUser() method.
@@ 986-1016 (lines=31) @@
983
     * @expectedExceptionMessage Argument 'userCreateStruct' is invalid: User with provided login already exists
984
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
985
     */
986
    public function testCreateUserThrowsInvalidArgumentException()
987
    {
988
        $repository = $this->getRepository();
989
990
        $editorsGroupId = $this->generateId('group', 13);
991
        /* BEGIN: Use Case */
992
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
993
        // Publish demo installation
994
995
        $userService = $repository->getUserService();
996
997
        // Instantiate a create struct with mandatory properties
998
        $userCreate = $userService->newUserCreateStruct(
999
            // admin is an existing login
1000
            'admin',
1001
            '[email protected]',
1002
            'secret',
1003
            'eng-US'
1004
        );
1005
1006
        $userCreate->setField('first_name', 'Example');
1007
        $userCreate->setField('last_name', 'User');
1008
1009
        // Load parent group for the user
1010
        $group = $userService->loadUserGroup($editorsGroupId);
1011
1012
        // This call will fail with a "InvalidArgumentException", because the
1013
        // user with "admin" login already exists.
1014
        $userService->createUser($userCreate, array($group));
1015
        /* END: Use Case */
1016
    }
1017
1018
    /**
1019
     * Test for the createUser() method.