Code Duplication    Length = 31-31 lines in 2 locations

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

@@ 926-956 (lines=31) @@
923
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
924
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
925
     */
926
    public function testCreateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
927
    {
928
        $repository = $this->getRepository();
929
930
        $editorsGroupId = $this->generateId('group', 13);
931
        /* BEGIN: Use Case */
932
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
933
        // Publish demo installation
934
935
        $userService = $repository->getUserService();
936
937
        // Instantiate a create struct with mandatory properties
938
        $userCreate = $userService->newUserCreateStruct(
939
            'user',
940
            '[email protected]',
941
            'secret',
942
            'eng-US'
943
        );
944
945
        // An object of stdClass is not a valid value for the field first_name
946
        $userCreate->setField('first_name', new \stdClass());
947
        $userCreate->setField('last_name', 'User');
948
949
        // Load parent group for the user
950
        $group = $userService->loadUserGroup($editorsGroupId);
951
952
        // This call will fail with an "InvalidArgumentException", because the
953
        // value for the firled "first_name" is not accepted by the field type.
954
        $userService->createUser($userCreate, array($group));
955
        /* END: Use Case */
956
    }
957
958
    /**
959
     * Test for the createUser() method.
@@ 966-996 (lines=31) @@
963
     * @expectedExceptionMessage Argument 'userCreateStruct' is invalid: User with provided login already exists
964
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
965
     */
966
    public function testCreateUserThrowsInvalidArgumentException()
967
    {
968
        $repository = $this->getRepository();
969
970
        $editorsGroupId = $this->generateId('group', 13);
971
        /* BEGIN: Use Case */
972
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
973
        // Publish demo installation
974
975
        $userService = $repository->getUserService();
976
977
        // Instantiate a create struct with mandatory properties
978
        $userCreate = $userService->newUserCreateStruct(
979
            // admin is an existing login
980
            'admin',
981
            '[email protected]',
982
            'secret',
983
            'eng-US'
984
        );
985
986
        $userCreate->setField('first_name', 'Example');
987
        $userCreate->setField('last_name', 'User');
988
989
        // Load parent group for the user
990
        $group = $userService->loadUserGroup($editorsGroupId);
991
992
        // This call will fail with a "InvalidArgumentException", because the
993
        // user with "admin" login already exists.
994
        $userService->createUser($userCreate, array($group));
995
        /* END: Use Case */
996
    }
997
998
    /**
999
     * Test for the createUser() method.