Code Duplication    Length = 31-31 lines in 2 locations

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

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