Code Duplication    Length = 31-31 lines in 2 locations

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

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