Minor refactoring

This commit is contained in:
Meritoo
2017-10-27 10:49:10 +02:00
parent 472807ee33
commit cdbee2991c
8 changed files with 80 additions and 78 deletions

View File

@@ -13,7 +13,7 @@ use Meritoo\Common\Exception\Method\DisabledMethodException;
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort; use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
/** /**
* Collection of participants (of surveys). * Collection of participants' short data.
* All participants grouped per survey. * All participants grouped per survey.
* *
* It's a collection of participants' collections. * It's a collection of participants' collections.

View File

@@ -36,7 +36,7 @@ class ParticipantService
private $client; private $client;
/** /**
* Collection of participants (of surveys). * Collection of participants' short data.
* All participants grouped per survey. * All participants grouped per survey.
* *
* @var Participants * @var Participants
@@ -47,7 +47,7 @@ class ParticipantService
* Class constructor * Class constructor
* *
* @param Client $client Client of the LimeSurvey's API * @param Client $client Client of the LimeSurvey's API
* @param Participants $allParticipants (optional) Collection of participants (of surveys). All participants * @param Participants $allParticipants (optional) Collection of participants' short data. All participants
* grouped per survey. * grouped per survey.
*/ */
public function __construct(Client $client, Participants $allParticipants = null) public function __construct(Client $client, Participants $allParticipants = null)
@@ -181,7 +181,7 @@ class ParticipantService
} }
/** /**
* Returns short data of one participant with given e-mail of given survey * Returns short data of one participant with given e-mail (participant of given survey)
* *
* @param int $surveyId ID of survey * @param int $surveyId ID of survey
* @param string $email E-mail address of the participant * @param string $email E-mail address of the participant
@@ -200,7 +200,7 @@ class ParticipantService
} }
/** /**
* Returns full data of participant with given e-mail of given survey * Returns full data of participant with given e-mail (participant of given survey)
* *
* @param int $surveyId ID of survey * @param int $surveyId ID of survey
* @param string $email E-mail address of the participant * @param string $email E-mail address of the participant

View File

@@ -17,7 +17,7 @@ use Meritoo\LimeSurvey\ApiClient\Result\Item\Participant;
use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort; use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
/** /**
* Test case of the collection of participants (of surveys) * Test case of the collection of participants' short data
* *
* @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl> * @author Krzysztof Niziol <krzysztof.niziol@meritoo.pl>
* @copyright Meritoo.pl * @copyright Meritoo.pl
@@ -25,7 +25,7 @@ use Meritoo\LimeSurvey\ApiClient\Result\Item\ParticipantShort;
class ParticipantsTest extends BaseTestCase class ParticipantsTest extends BaseTestCase
{ {
/** /**
* An empty collection of participants (of surveys) * An empty collection of participants' short data
* *
* @var Participants * @var Participants
*/ */

View File

@@ -127,12 +127,24 @@ class ParticipantShortTest extends BaseTestCase
static::assertEquals($participant2->getEmail(), $participantShort2->getEmail()); static::assertEquals($participant2->getEmail(), $participantShort2->getEmail());
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getParticipantsRawData();
$this->participant1stInstance = new ParticipantShort($this->rawData[0]);
$this->participant2ndInstance = new ParticipantShort($this->rawData[1]);
}
/** /**
* Returns raw data of participants * Returns raw data of participants
* *
* @return array * @return array
*/ */
public static function getParticipantsRawData() private static function getParticipantsRawData()
{ {
return [ return [
[ [
@@ -153,16 +165,4 @@ class ParticipantShortTest extends BaseTestCase
], ],
]; ];
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getParticipantsRawData();
$this->participant1stInstance = new ParticipantShort($this->rawData[0]);
$this->participant2ndInstance = new ParticipantShort($this->rawData[1]);
}
} }

View File

@@ -159,12 +159,24 @@ class ParticipantTest extends BaseTestCase
static::assertNull($this->participant2ndInstance->getValidUntil()); static::assertNull($this->participant2ndInstance->getValidUntil());
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getParticipantsRawData();
$this->participant1stInstance = new Participant($this->rawData[0]);
$this->participant2ndInstance = new Participant($this->rawData[1]);
}
/** /**
* Returns raw data of participants * Returns raw data of participants
* *
* @return array * @return array
*/ */
public static function getParticipantsRawData() private static function getParticipantsRawData()
{ {
return [ return [
[ [
@@ -207,16 +219,4 @@ class ParticipantTest extends BaseTestCase
], ],
]; ];
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getParticipantsRawData();
$this->participant1stInstance = new Participant($this->rawData[0]);
$this->participant2ndInstance = new Participant($this->rawData[1]);
}
} }

View File

@@ -158,12 +158,24 @@ class QuestionShortTest extends BaseTestCase
static::assertEquals('HR', $this->question2ndInstance->getModuleName()); static::assertEquals('HR', $this->question2ndInstance->getModuleName());
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getQuestionsRawData();
$this->question1stInstance = new QuestionShort($this->rawData[0]);
$this->question2ndInstance = new QuestionShort($this->rawData[1]);
}
/** /**
* Returns raw data of questions * Returns raw data of questions
* *
* @return array * @return array
*/ */
public static function getQuestionsRawData() private static function getQuestionsRawData()
{ {
return [ return [
[ [
@@ -214,16 +226,4 @@ class QuestionShortTest extends BaseTestCase
], ],
]; ];
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getQuestionsRawData();
$this->question1stInstance = new QuestionShort($this->rawData[0]);
$this->question2ndInstance = new QuestionShort($this->rawData[1]);
}
} }

View File

@@ -194,12 +194,24 @@ class QuestionTest extends BaseTestCase
static::assertNull($this->question2ndInstance->getDefaultValue()); static::assertNull($this->question2ndInstance->getDefaultValue());
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getQuestionsRawData();
$this->question1stInstance = new Question($this->rawData[0]);
$this->question2ndInstance = new Question($this->rawData[1]);
}
/** /**
* Returns raw data of questions * Returns raw data of questions
* *
* @return array * @return array
*/ */
public static function getQuestionsRawData() private static function getQuestionsRawData()
{ {
return [ return [
[ [
@@ -276,16 +288,4 @@ class QuestionTest extends BaseTestCase
], ],
]; ];
} }
/**
* {@inheritdoc}
*/
protected function setUp()
{
parent::setUp();
$this->rawData = static::getQuestionsRawData();
$this->question1stInstance = new Question($this->rawData[0]);
$this->question2ndInstance = new Question($this->rawData[1]);
}
} }

View File

@@ -183,13 +183,14 @@ class ParticipantServiceTest extends BaseTestCase
$this->createServiceWithoutParticipants($rpcClientManager, $sessionManager); $this->createServiceWithoutParticipants($rpcClientManager, $sessionManager);
$this->createServiceWithParticipants($rpcClientManager, $sessionManager); $this->createServiceWithParticipants($rpcClientManager, $sessionManager);
static::assertNull($this->serviceWithoutParticipants->getParticipant(1, 'john@scott.com')); $participant1 = $this->serviceWithoutParticipants->getParticipant(1, 'john@scott.com');
$participant = $this->serviceWithParticipants->getParticipant(1, 'john@scott.com'); $participant2 = $this->serviceWithParticipants->getParticipant(1, 'john@scott.com');
static::assertInstanceOf(ParticipantShort::className, $participant); static::assertNull($participant1);
static::assertEquals('John', $participant->getFirstName()); static::assertInstanceOf(ParticipantShort::className, $participant2);
static::assertEquals('Scott', $participant->getLastName()); static::assertEquals('John', $participant2->getFirstName());
static::assertEquals('john@scott.com', $participant->getEmail()); static::assertEquals('Scott', $participant2->getLastName());
static::assertEquals('john@scott.com', $participant2->getEmail());
} }
public function testGetParticipantDetails() public function testGetParticipantDetails()
@@ -212,22 +213,23 @@ class ParticipantServiceTest extends BaseTestCase
$rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults); $rpcClientManager = $this->getJsonRpcClientManager(1, $runMethodCallResults);
$this->createServiceWithParticipants($rpcClientManager, $sessionManager); $this->createServiceWithParticipants($rpcClientManager, $sessionManager);
static::assertNull($this->serviceWithoutParticipants->getParticipantDetails(1, 'john@scott.com')); $participant1 = $this->serviceWithoutParticipants->getParticipantDetails(1, 'john@scott.com');
$participant = $this->serviceWithParticipants->getParticipantDetails(1, 'john@scott.com'); $participant2 = $this->serviceWithParticipants->getParticipantDetails(1, 'john@scott.com');
static::assertInstanceOf(Participant::className, $participant); static::assertNull($participant1);
static::assertEquals($runMethodCallResults['tid'], $participant->getId()); static::assertInstanceOf(Participant::className, $participant2);
static::assertEquals($runMethodCallResults['firstname'], $participant->getFirstName()); static::assertEquals($runMethodCallResults['tid'], $participant2->getId());
static::assertEquals($runMethodCallResults['lastname'], $participant->getLastName()); static::assertEquals($runMethodCallResults['firstname'], $participant2->getFirstName());
static::assertEquals($runMethodCallResults['email'], $participant->getEmail()); static::assertEquals($runMethodCallResults['lastname'], $participant2->getLastName());
static::assertEquals($runMethodCallResults['token'], $participant->getToken()); static::assertEquals($runMethodCallResults['email'], $participant2->getEmail());
static::assertFalse($participant->isSent()); static::assertEquals($runMethodCallResults['token'], $participant2->getToken());
static::assertFalse($participant->isCompleted()); static::assertFalse($participant2->isSent());
static::assertNull($participant->isBlacklisted()); static::assertFalse($participant2->isCompleted());
static::assertNull($participant->getValidFrom()); static::assertNull($participant2->isBlacklisted());
static::assertNull($participant2->getValidFrom());
} }
public function testHasParticipantFilledSurveyWithException() public function testHasParticipantFilledSurveyWithoutParticipants()
{ {
$this->setExpectedException(MissingParticipantOfSurveyException::className); $this->setExpectedException(MissingParticipantOfSurveyException::className);