Tests - add missing tests of Participants::addParticipant() method for not existing survey

This commit is contained in:
Meritoo
2017-09-29 19:47:42 +02:00
parent d54765b378
commit bbd466610c
3 changed files with 43 additions and 5 deletions

View File

@@ -12,6 +12,13 @@ use Meritoo\Common\Type\Base\BaseType;
*/ */
class ReasonType extends 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 * Reason of exception when there is no participants of survey
* *

View File

@@ -126,8 +126,29 @@ class ParticipantServiceTest extends BaseTestCase
static::assertFalse($this->serviceWithParticipants->hasParticipant(3, 'john@scott.com')); 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() public function testAddParticipant()
{ {
$surveyId = 1;
$firstName = 'John'; $firstName = 'John';
$lastName = 'Scott'; $lastName = 'Scott';
$email = 'john@scott.com'; $email = 'john@scott.com';
@@ -143,10 +164,14 @@ class ParticipantServiceTest extends BaseTestCase
$rpcClientManager = $this->getJsonRpcClientManager($runMethodCallCount, $runMethodCallResults); $rpcClientManager = $this->getJsonRpcClientManager($runMethodCallCount, $runMethodCallResults);
$sessionManager = $this->getSessionManager(); $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::assertInstanceOf(Participant::class, $result);
static::assertEquals($firstName, $result->getFirstName());
static::assertEquals($lastName, $result->getLastName());
static::assertEquals($email, $result->getEmail());
} }
public function testGetParticipant() public function testGetParticipant()

View File

@@ -30,9 +30,10 @@ class ReasonTypeTest extends BaseTypeTestCase
protected function getAllExpectedTypes() protected function getAllExpectedTypes()
{ {
return [ return [
'NO_PARTICIPANTS_FOUND' => ReasonType::NO_PARTICIPANTS_FOUND, 'NOT_EXISTING_SURVEY_ID' => ReasonType::NOT_EXISTING_SURVEY_ID,
'NO_SURVEYS_FOUND' => ReasonType::NO_SURVEYS_FOUND, 'NO_PARTICIPANTS_FOUND' => ReasonType::NO_PARTICIPANTS_FOUND,
'NO_TOKEN_TABLE' => ReasonType::NO_TOKEN_TABLE, 'NO_SURVEYS_FOUND' => ReasonType::NO_SURVEYS_FOUND,
'NO_TOKEN_TABLE' => ReasonType::NO_TOKEN_TABLE,
]; ];
} }
@@ -59,6 +60,11 @@ class ReasonTypeTest extends BaseTypeTestCase
false, false,
]; ];
yield[
ReasonType::NOT_EXISTING_SURVEY_ID,
true,
];
yield[ yield[
ReasonType::NO_PARTICIPANTS_FOUND, ReasonType::NO_PARTICIPANTS_FOUND,
true, true,