Ejemplo n.º 1
0
use OGabrielSantos\OrdinationService\Test\Answers\Answer;
use OGabrielSantos\OrdinationService\Test\Answers\AnswerCollection;
use OGabrielSantos\OrdinationService\Candidates\Candidate;
use OGabrielSantos\OrdinationService\Candidates\CandidateCollection;
use OGabrielSantos\OrdinationService\OrdinationService;
use OGabrielSantos\OrdinationService\Candidates\Filters\Name;
use OGabrielSantos\OrdinationService\Candidates\Filters\State;
use OGabrielSantos\OrdinationService\Candidates\Filters\Email;
$questionList = new QuestionCollection([new Question('Em PHP, qual o resultado da..', new AnswerCollection([new Answer('A', '11'), new Answer('B', '13'), new Answer('C', '10'), new Answer('D', '12'), new Answer('E', 'NDA.')]), new Answer('A', '11'), 100), new Question('Como é possível realizar..', new AnswerCollection([new Answer('A', 'Somente através..'), new Answer('B', 'Nunca pela..'), new Answer('C', 'Através da..'), new Answer('D', 'Apenas com a..'), new Answer('E', 'NDA.')]), new Answer('C', 'Através da..'), 200), new Question('Em PHP, qual o resultado da..', new AnswerCollection([new Answer('A', '10bananas20laranjas'), new Answer('B', "''"), new Answer('C', '0'), new Answer('D', '30'), new Answer('E', 'NDA.')]), new Answer('D', '30'), 150), new Question('Quais são os 5 princípios..', new AnswerCollection([new Answer('A', 'Single responsibility principle..'), new Answer('B', 'Single responsibility principle..'), new Answer('C', 'Single responsibility principle..'), new Answer('D', 'Singleton principle'), new Answer('E', 'NDA.')]), new Answer('B', 'Single responsibility principle..'), 300)]);
$candidatesList = new CandidateCollection([new Candidate(1, 'Kent Beck', '*****@*****.**', 'SC', new AnswersList('A,C,D,B')), new Candidate(2, 'Eric Evans', '*****@*****.**', 'DF', new AnswersList('B,C,A,E')), new Candidate(3, 'Martin Fowler', '*****@*****.**', 'SP', new AnswersList('E,A,B,E')), new Candidate(4, 'Alan Kay', '*****@*****.**', 'SC', new AnswersList('A,C,E,E')), new Candidate(5, 'Robert C. Martin', '*****@*****.**', 'RS', new AnswersList('E,B,D,B'))]);
$test = new Test('2013-10-25', $questionList);
// 1, 5, 4, 2, 3
$ordinationService = new OrdinationService($test, $candidatesList);
$ordinationService->reorder();
echo $ordinationService->getOrdered() . "\n";
// 1, 4
$ordinationService = new OrdinationService($test, $candidatesList);
$ordinationService->filter(State::equal('SC'));
$ordinationService->reorder();
echo $ordinationService->getOrdered() . "\n";
// 5, 4, 2, 3
$ordinationService = new OrdinationService($test, $candidatesList);
$ordinationService->filter(Name::contain('A'));
$ordinationService->reorder();
echo $ordinationService->getOrdered() . "\n";
// 4, 3
$ordinationService = new OrdinationService($test, $candidatesList);
$ordinationService->filter(Name::contain('A'));
$ordinationService->filter(Email::contain('L'));
$ordinationService->reorder();
echo $ordinationService->getOrdered() . "\n";
 /**
  * @test
  */
 public function serviceShouldReorderWithNameAndEmailFilter()
 {
     $ordinationService = new OrdinationService($this->test, $this->candidates);
     $ordinationService->filter(Name::contain('A'));
     $ordinationService->filter(Email::contain('L'));
     $ordinationService->reorder();
     $this->assertEquals("Candidatos:\n4, 3", $ordinationService->getOrdered());
 }