Code Duplication    Length = 31-31 lines in 2 locations

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

@@ 893-923 (lines=31) @@
890
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
891
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
892
     */
893
    public function testCreateUserThrowsInvalidArgumentExceptionOnFieldTypeNotAccept()
894
    {
895
        $repository = $this->getRepository();
896
897
        $editorsGroupId = $this->generateId('group', 13);
898
        /* BEGIN: Use Case */
899
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
900
        // Publish demo installation
901
902
        $userService = $repository->getUserService();
903
904
        // Instantiate a create struct with mandatory properties
905
        $userCreate = $userService->newUserCreateStruct(
906
            'user',
907
            '[email protected]',
908
            'secret',
909
            'eng-US'
910
        );
911
912
        // An object of stdClass is not a valid value for the field first_name
913
        $userCreate->setField('first_name', new \stdClass());
914
        $userCreate->setField('last_name', 'User');
915
916
        // Load parent group for the user
917
        $group = $userService->loadUserGroup($editorsGroupId);
918
919
        // This call will fail with an "InvalidArgumentException", because the
920
        // value for the firled "first_name" is not accepted by the field type.
921
        $userService->createUser($userCreate, array($group));
922
        /* END: Use Case */
923
    }
924
925
    /**
926
     * Test for the createUser() method.
@@ 932-962 (lines=31) @@
929
     * @expectedException \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
930
     * @depends eZ\Publish\API\Repository\Tests\UserServiceTest::testCreateUser
931
     */
932
    public function testCreateUserThrowsInvalidArgumentException()
933
    {
934
        $repository = $this->getRepository();
935
936
        $editorsGroupId = $this->generateId('group', 13);
937
        /* BEGIN: Use Case */
938
        // $editorsGroupId is the ID of the "Editors" user group in an eZ
939
        // Publish demo installation
940
941
        $userService = $repository->getUserService();
942
943
        // Instantiate a create struct with mandatory properties
944
        $userCreate = $userService->newUserCreateStruct(
945
            // admin is an existing login
946
            'admin',
947
            '[email protected]',
948
            'secret',
949
            'eng-US'
950
        );
951
952
        $userCreate->setField('first_name', 'Example');
953
        $userCreate->setField('last_name', 'User');
954
955
        // Load parent group for the user
956
        $group = $userService->loadUserGroup($editorsGroupId);
957
958
        // This call will fail with a "InvalidArgumentException", because the
959
        // user with "admin" login already exists.
960
        $userService->createUser($userCreate, array($group));
961
        /* END: Use Case */
962
    }
963
964
    /**
965
     * Test for the createUser() method.