Code Duplication    Length = 31-31 lines in 2 locations

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

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