diff --git a/src/Type/ReasonType.php b/src/Type/ReasonType.php index e50fea3..3b7ca81 100644 --- a/src/Type/ReasonType.php +++ b/src/Type/ReasonType.php @@ -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 * diff --git a/tests/Service/ParticipantServiceTest.php b/tests/Service/ParticipantServiceTest.php index 65052ed..0f02a8d 100644 --- a/tests/Service/ParticipantServiceTest.php +++ b/tests/Service/ParticipantServiceTest.php @@ -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() diff --git a/tests/Type/ReasonTypeTest.php b/tests/Type/ReasonTypeTest.php index cf3af64..cb86bf8 100644 --- a/tests/Type/ReasonTypeTest.php +++ b/tests/Type/ReasonTypeTest.php @@ -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,