mirror of
https://github.com/wiosna-dev/limesurvey-api-client.git
synced 2026-03-12 02:11:45 +01:00
Tests - add missing tests of Participants::addParticipant() method for not existing survey
This commit is contained in:
@@ -12,6 +12,13 @@ use Meritoo\Common\Type\Base\BaseType;
|
||||
*/
|
||||
class ReasonType extends BaseType
|
||||
{
|
||||
/**
|
||||
* Reason of exception when there is no survey with given ID
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const NOT_EXISTING_SURVEY_ID = 'Error: Invalid survey ID';
|
||||
|
||||
/**
|
||||
* Reason of exception when there is no participants of survey
|
||||
*
|
||||
|
||||
@@ -126,8 +126,29 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
static::assertFalse($this->serviceWithParticipants->hasParticipant(3, 'john@scott.com'));
|
||||
}
|
||||
|
||||
public function testAddParticipantForNotExistingSurvey()
|
||||
{
|
||||
$this->expectException(CannotProcessDataException::class);
|
||||
$exception = new CannotProcessDataException(ReasonType::NOT_EXISTING_SURVEY_ID);
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManagerWithException(1, $exception);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$this->createServiceWithParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
|
||||
$this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
$this->serviceWithParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
}
|
||||
|
||||
public function testAddParticipant()
|
||||
{
|
||||
$surveyId = 1;
|
||||
$firstName = 'John';
|
||||
$lastName = 'Scott';
|
||||
$email = 'john@scott.com';
|
||||
@@ -143,10 +164,14 @@ class ParticipantServiceTest extends BaseTestCase
|
||||
|
||||
$rpcClientManager = $this->getJsonRpcClientManager($runMethodCallCount, $runMethodCallResults);
|
||||
$sessionManager = $this->getSessionManager();
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
|
||||
$result = $this->serviceWithoutParticipants->addParticipant(1, $firstName, $lastName, $email);
|
||||
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
|
||||
$result = $this->serviceWithoutParticipants->addParticipant($surveyId, $firstName, $lastName, $email);
|
||||
|
||||
static::assertInstanceOf(Participant::class, $result);
|
||||
static::assertEquals($firstName, $result->getFirstName());
|
||||
static::assertEquals($lastName, $result->getLastName());
|
||||
static::assertEquals($email, $result->getEmail());
|
||||
}
|
||||
|
||||
public function testGetParticipant()
|
||||
|
||||
@@ -30,9 +30,10 @@ class ReasonTypeTest extends BaseTypeTestCase
|
||||
protected function getAllExpectedTypes()
|
||||
{
|
||||
return [
|
||||
'NO_PARTICIPANTS_FOUND' => ReasonType::NO_PARTICIPANTS_FOUND,
|
||||
'NO_SURVEYS_FOUND' => ReasonType::NO_SURVEYS_FOUND,
|
||||
'NO_TOKEN_TABLE' => ReasonType::NO_TOKEN_TABLE,
|
||||
'NOT_EXISTING_SURVEY_ID' => ReasonType::NOT_EXISTING_SURVEY_ID,
|
||||
'NO_PARTICIPANTS_FOUND' => ReasonType::NO_PARTICIPANTS_FOUND,
|
||||
'NO_SURVEYS_FOUND' => ReasonType::NO_SURVEYS_FOUND,
|
||||
'NO_TOKEN_TABLE' => ReasonType::NO_TOKEN_TABLE,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -59,6 +60,11 @@ class ReasonTypeTest extends BaseTypeTestCase
|
||||
false,
|
||||
];
|
||||
|
||||
yield[
|
||||
ReasonType::NOT_EXISTING_SURVEY_ID,
|
||||
true,
|
||||
];
|
||||
|
||||
yield[
|
||||
ReasonType::NO_PARTICIPANTS_FOUND,
|
||||
true,
|
||||
|
||||
Reference in New Issue
Block a user