controller = new ControllerCandidate(); } /** * @throws \PHPUnit\Framework\MockObject\Exception * @throws Exception */ public function testGoToForm(): void { $modelMock = $this->createMock(ModelCandidate::class); $modelMock->expects($this->once()) ->method('getForm') ->willReturn('
'); $this->controller->goToForm(); $this->expectOutputRegex('/
.*<\/form>/s'); } public function testGoToAdminLogin(): void { global $rep, $views; $this->controller->goToAdminLogin(); $this->expectOutputString(file_get_contents($rep . $views['adminLogin'])); } /** * @throws \PHPUnit\Framework\MockObject\Exception * @throws Exception */ public function testSubmitForm(): void { $modelMock = $this->createMock(ModelCandidate::class); $modelMock->expects($this->once()) ->method('submitForm'); $this->controller->submitForm(); $this->expectOutputRegex('/' . preg_quote('Location: ?thanks', '/') . '/'); } public function testGoToThanks(): void { global $rep, $views; $this->controller->goToThanks(); $this->expectOutputString(file_get_contents($rep . $views['thanks'])); } /** * @throws \PHPUnit\Framework\MockObject\Exception */ public function testLoginAsAdmin(): void { global $rep, $views; $_SESSION['role'] = 'Admin'; $modelMock = $this->createMock(ModelCandidate::class); $modelMock->expects($this->once()) ->method('login'); $this->controller->login(); $this->expectOutputString(file_get_contents($rep . $views['admin'])); } /** * @throws \PHPUnit\Framework\MockObject\Exception */ public function testLoginAsNonAdmin(): void { global $rep, $views; $_SESSION['role'] = 'NonAdmin'; $modelMock = $this->createMock(ModelCandidate::class); $modelMock->expects($this->once()) ->method('login'); $this->controller->login(); $this->expectOutputString(file_get_contents($rep . $views['adminLogin'])); } /** * @throws \PHPUnit\Framework\MockObject\Exception */ public function testLoginWithException(): void { global $rep, $views; $_SESSION['role'] = 'NonAdmin'; $modelMock = $this->createMock(ModelCandidate::class); $modelMock->expects($this->once()) ->method('login') ->willThrowException(new Exception('Invalid credentials')); $this->controller->login(); $this->expectOutputString(file_get_contents($rep . $views['adminLogin'])); } }