fork download
  1. <?php
  2. namespace Tests\TestHubBundle\Service;
  3.  
  4. use TestHubBundle\Entity\Attempt;
  5. use TestHubBundle\Entity\DecimalAnswer;
  6. use TestHubBundle\Entity\QuestionWithDecimalAnswer;
  7. use TestHubBundle\Entity\QuestionWithMultipleCorrectAnswers;
  8. use TestHubBundle\Entity\QuestionWithSingleCorrectAnswer;
  9. use TestHubBundle\Entity\QuestionWithTextAnswer;
  10. use TestHubBundle\Entity\Test;
  11. use TestHubBundle\Entity\TextAnswer;
  12. use TestHubBundle\Entity\Variant;
  13. use TestHubBundle\Entity\VariantAnswer;
  14. use TestHubBundle\Service\Calculator;
  15.  
  16. class CalculatorTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public function testCalculateMark()
  19. {
  20. $attempt = new Attempt();
  21. $test = new Test();
  22. $attempt->setTest($test);
  23.  
  24. /**
  25.   * First question (with correct answer)
  26.   */
  27. $question1 = new QuestionWithSingleCorrectAnswer();
  28. $question1->setId(1);
  29. $question1->setDescription("Сколько будет 5 - 2 (пять минус два) ?");
  30. $question1->setPoints(10);
  31. $question1->setTest($test);
  32. $question1->setSequenceNumber(1);
  33.  
  34. $variant1 = new Variant();
  35. $variant1->setId(1);
  36. $variant1->setValue("7");
  37. $variant1->setIsRight("no");
  38. $variant2 = new Variant();
  39. $variant2->setId(2);
  40. $variant2->setValue("3");
  41. $variant2->setIsRight("yes");
  42. $variant3 = new Variant();
  43. $variant3->setId(3);
  44. $variant3->setValue("2");
  45. $variant3->setIsRight("no");
  46. $variant4 = new Variant();
  47. $variant4->setId(4);
  48. $variant4->setValue("ни один из вариантов");
  49. $variant4->setIsRight("no");
  50. $question1->setVariants([$variant1, $variant2, $variant3, $variant4]);
  51.  
  52. $answer1 = new VariantAnswer();
  53. $answer1->setAttempt($attempt);
  54. $answer1->setQuestion($question1);
  55. $answer1->setVariant($variant2);
  56.  
  57. /**
  58.   * Second question (with correct answer)
  59.   */
  60. $question2 = new QuestionWithTextAnswer();
  61. $question2->setId(2);
  62. $question2->setDescription(
  63. "Как называется этот значок \"+\"?" .
  64. "Подсказка: 4 буквы, начинается с \"п\", заканчивается на \"люс\"."
  65. );
  66. $question2->setPoints(5);
  67. $question2->setTest($test);
  68. $question2->setSequenceNumber(2);
  69. $question2->setAnswerText("плюс");
  70.  
  71. $answer2 = new TextAnswer();
  72. $answer2->setAttempt($attempt);
  73. $answer2->setQuestion($question2);
  74. $answer2->setTextAnswer("плюс");
  75.  
  76. /**
  77.   * Third question (with wrong answer)
  78.   */
  79. $question3 = new QuestionWithDecimalAnswer();
  80. $question3->setId(3);
  81. $question3->setDescription(
  82. "Сколько будет 2 + 2 (два плюс два)? Ответ дать числом."
  83. );
  84. $question3->setPoints(5);
  85. $question3->setTest($test);
  86. $question3->setSequenceNumber(3);
  87. $question3->setAnswerDecimal("4");
  88.  
  89. $answer3 = new DecimalAnswer();
  90. $answer3->setAttempt($attempt);
  91. $answer3->setQuestion($question3);
  92. $answer3->setDecimalAnswer("5.5");
  93.  
  94. /**
  95.   * Fourth question (without answer, i.e. skipped)
  96.   */
  97. $variant5 = new Variant();
  98. $variant5->setId(5);
  99. $variant5->setValue("число 5 положительное");
  100. $variant5->setIsRight("yes");
  101. $variant6 = new Variant();
  102. $variant6->setId(6);
  103. $variant6->setValue("число 5 больше нуля");
  104. $variant6->setIsRight("yes");
  105. $variant7 = new Variant();
  106. $variant7->setId(7);
  107. $variant7->setValue("число 5 меньше нуля");
  108. $variant7->setIsRight("no");
  109. $variant8 = new Variant();
  110. $variant8->setId(8);
  111. $variant8->setValue("число 5 четное");
  112. $variant8->setIsRight("no");
  113.  
  114. $question4 = new QuestionWithMultipleCorrectAnswers();
  115. $question4->setId(4);
  116. $question4->setDescription("Выберите правильные утверждения");
  117. $question4->setPoints(10);
  118. $question4->setTest($test);
  119. $question4->setSequenceNumber(4);
  120. $question4->setVariants([$variant5, $variant6, $variant7, $variant8]);
  121.  
  122. /**
  123.   * Attach questions and answers
  124.   */
  125. $test->setQuestions([$question1, $question2, $question3, $question4]);
  126. $attempt->setAnswers([$answer1, $answer2, $answer3]);
  127.  
  128. /**
  129.   * Finally test itself
  130.   */
  131. $calculator = new Calculator();
  132. $mark = $calculator->calculateMark($attempt);
  133. $this->assertInternalType('integer', $mark);
  134. $this->assertEquals(15, $mark);
  135. }
  136. }
  137.  
Runtime error #stdin #stdout #stderr 0.02s 52432KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Class 'PHPUnit_Framework_TestCase' not found in /home/tpIzu8/prog.php on line 17