Last active
June 30, 2024 14:24
-
-
Save trikitrok/1ad86a94b0e6d91dbd01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SendingFormByEmailAndRedirectingTest extends PHPUnit_Framework_TestCase | |
{ | |
private $form; | |
private $formRedirection; | |
private $email; | |
private $sendAndRedirectAction; | |
private $WHATEVER_FIELDS; | |
function setUp() | |
{ | |
$this->WHATEVER_FIELDS = | |
array("fieldName" => "fieldContent"); | |
$this->form = Phake::mock('Form'); | |
$this->formRedirection = Phake::mock('FormRedirection'); | |
$this->email = Phake::mock('FormEmail'); | |
$this->sendAndRedirectAction = | |
new SendingFormByEmailAndRedirecting( | |
$this->email, | |
$this->form, | |
$this->formRedirection | |
); | |
} | |
function testRedirectionBackToFormPage() | |
{ | |
$this->whenFormNotFilled(); | |
$this->sendAndRedirectAction->execute(); | |
Phake::verify($this->formRedirection) | |
->backToFormPage(); | |
} | |
function testEmailSending() | |
{ | |
$this->whenFormFilledWithWhateverFields(); | |
$this->sendAndRedirectAction->execute(); | |
Phake::verify($this->email) | |
->send($this->WHATEVER_FIELDS); | |
} | |
function testRedirectionToSuccesPage() | |
{ | |
$this->whenFormFilledWithWhateverFields(); | |
$this->andEmailSentSuccessfully(); | |
$this->sendAndRedirectAction->execute(); | |
Phake::verify($this->formRedirection)->toSuccessPage(); | |
} | |
function testRedirectionToFailPage() | |
{ | |
$this->whenFormFilledWithWhateverFields(); | |
$this->andEmailNotSentSuccessfully(); | |
$this->sendAndRedirectAction->execute(); | |
Phake::verify($this->formRedirection)->toFailPage(); | |
} | |
private function whenFormFilledWithWhateverFields() { | |
Phake::when($this->form) | |
->isNotFilled() | |
->thenReturn(false); | |
Phake::when($this->form) | |
->fields() | |
->thenReturn($this->WHATEVER_FIELDS); | |
} | |
private function whenFormNotFilled() | |
{ | |
Phake::when($this->form) | |
->isNotFilled() | |
->thenReturn(true); | |
} | |
private function andEmailSentSuccessfully() | |
{ | |
Phake::when($this->email) | |
->send($this->WHATEVER_FIELDS) | |
->thenReturn(true); | |
} | |
private function andEmailNotSentSuccessfully() | |
{ | |
Phake::when($this->email) | |
->send($this->WHATEVER_FIELDS) | |
->thenReturn(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment