expectException(InvalidArgumentException::class); $controller->addQuestion(); } /** * @throws Exception * @throws \Exception */ public function testAddQuestionCallsModelAdminAndGoesToQuestionsWhenTypeIsTextQuestion() { $modelMock = $this->createMock(ModelAdmin::class); $modelMock->expects($this->once())->method('addQuestion'); $controller = new ControllerAdmin(); $controller->goToQuestions = $this->createMock(stdClass::class); // mock the method $_POST['type'] = 'BusinessClass\TextQuestion'; $controller->addQuestion(); } /** * @throws Exception * @throws \Exception */ public function testAddQuestionCallsModelAdminAndRequiresPossibleResponsesFormWhenTypeIsNotTextQuestion() { $modelMock = $this->createMock(ModelAdmin::class); $modelMock->expects($this->once())->method('addQuestion'); $modelMock->expects($this->once())->method('getCategories'); $controller = new ControllerAdmin(); $controller->goToQuestions = $this->createMock(stdClass::class); // mock the method $_POST['type'] = 'BusinessClass\OtherQuestion'; $GLOBALS['rep'] = 'path/to/'; $GLOBALS['views'] = ['possibleResponsesForm' => 'path/to/possibleResponsesForm.php']; $this->expectOutputString(file_get_contents('path/to/possibleResponsesForm.php')); $controller->addQuestion(); } /** * @throws \Exception */ public function testAddResponseThrowsExceptionWhenParametersAreMissing() { $controller = new ControllerAdmin(); $_POST = []; $this->expectException(InvalidArgumentException::class); $controller->addResponse(); } /** * @throws Exception * @throws \Exception */ public function testAddResponseCallsModelAdminAndRequiresContinueWhenParametersAreValid() { $modelMock = $this->createMock(ModelAdmin::class); $modelMock->expects($this->once())->method('addResponse'); $modelMock->expects($this->once())->method('getCategories'); $controller = new ControllerAdmin(); $GLOBALS['rep'] = 'path/to/'; $GLOBALS['views'] = ['continue' => 'path/to/continue.php']; $_POST['idQuestion'] = '123'; $_POST['question'] = 'What is the meaning of life?'; $_POST['type'] = 'BusinessClass\OtherQuestion'; $this->expectOutputString(file_get_contents('path/to/continue.php')); $controller->addResponse(); } /** * @throws \Exception */ public function testContinueResponseThrowsExceptionWhenParametersAreMissing() { $controller = new ControllerAdmin(); $_POST = []; $this->expectException(InvalidArgumentException::class); $controller->continueResponse(); } }