|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\Fundraising\Frontend\Tests\Integration\ApplicationContext\UseCases\GetInTouch; |
|
6
|
|
|
|
|
7
|
|
|
use WMDE\Fundraising\Frontend\ApplicationContext\UseCases\GetInTouch\GetInTouchRequest; |
|
8
|
|
|
use WMDE\Fundraising\Frontend\ApplicationContext\UseCases\GetInTouch\GetInTouchUseCase; |
|
9
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\OperatorMailer; |
|
10
|
|
|
use WMDE\Fundraising\Frontend\Infrastructure\TemplateBasedMailer; |
|
11
|
|
|
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\EmailAddress; |
|
12
|
|
|
use WMDE\Fundraising\Frontend\Tests\Fixtures\TemplateBasedMailerSpy; |
|
13
|
|
|
use WMDE\Fundraising\Frontend\Validation\GetInTouchValidator; |
|
14
|
|
|
use WMDE\Fundraising\Frontend\Validation\ValidationResult; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @covers WMDE\Fundraising\Frontend\ApplicationContext\UseCases\GetInTouch\GetInTouchUseCase |
|
18
|
|
|
* |
|
19
|
|
|
* @license GNU GPL v2+ |
|
20
|
|
|
* @author Kai Nissen < [email protected] > |
|
21
|
|
|
*/ |
|
22
|
|
|
class GetInTouchUseCaseTest extends \PHPUnit_Framework_TestCase { |
|
23
|
|
|
|
|
24
|
|
|
const INQUIRER_FIRST_NAME = 'Curious'; |
|
25
|
|
|
const INQUIRER_LAST_NAME = 'Guy'; |
|
26
|
|
|
const INQUIRER_EMAIL_ADDRESS = '[email protected]'; |
|
27
|
|
|
const INQUIRY_SUBJECT = 'Please let me know'; |
|
28
|
|
|
const INQUIRY_MESSAGE = 'What is it you do?'; |
|
29
|
|
|
|
|
30
|
|
|
private $validator; |
|
31
|
|
|
|
|
32
|
|
|
/** @var OperatorMailer|\PHPUnit_Framework_MockObject_MockObject */ |
|
33
|
|
|
private $operatorMailer; |
|
34
|
|
|
|
|
35
|
|
|
/** @var TemplateBasedMailerSpy */ |
|
36
|
|
|
private $userMailer; |
|
37
|
|
|
|
|
38
|
|
|
public function setUp() { |
|
39
|
|
|
$this->validator = $this->newSucceedingValidator(); |
|
40
|
|
|
$this->operatorMailer = $this->createMock( OperatorMailer::class ); |
|
41
|
|
|
$this->userMailer = new TemplateBasedMailerSpy( $this ); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
private function newGetInTouchUseCase(): GetInTouchUseCase { |
|
45
|
|
|
return new GetInTouchUseCase( |
|
46
|
|
|
$this->validator, |
|
47
|
|
|
$this->operatorMailer, |
|
48
|
|
|
$this->userMailer |
|
49
|
|
|
); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testGivenValidParameters_theyAreContainedInTheEmailToOperator() { |
|
53
|
|
|
$this->operatorMailer->expects( $this->once() ) |
|
|
|
|
|
|
54
|
|
|
->method( 'sendMailToOperator' ) |
|
55
|
|
|
->with( |
|
56
|
|
|
$this->equalTo( new EmailAddress( self::INQUIRER_EMAIL_ADDRESS ) ), |
|
57
|
|
|
$this->equalTo( [ |
|
58
|
|
|
'firstName' => self::INQUIRER_FIRST_NAME, |
|
59
|
|
|
'lastName' => self::INQUIRER_LAST_NAME, |
|
60
|
|
|
'emailAddress' => self::INQUIRER_EMAIL_ADDRESS, |
|
61
|
|
|
'subject' => self::INQUIRY_SUBJECT, |
|
62
|
|
|
'message' => self::INQUIRY_MESSAGE |
|
63
|
|
|
] ) |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$useCase = $this->newGetInTouchUseCase(); |
|
67
|
|
|
$useCase->processContactRequest( $this->newRequest() ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function testGivenValidRequest_theUserIsNotified() { |
|
71
|
|
|
$useCase = $this->newGetInTouchUseCase(); |
|
72
|
|
|
$useCase->processContactRequest( $this->newRequest() ); |
|
73
|
|
|
|
|
74
|
|
|
$this->userMailer->assertCalledOnce(); |
|
75
|
|
|
$this->userMailer->assertCalledOnceWith( |
|
76
|
|
|
new EmailAddress( self::INQUIRER_EMAIL_ADDRESS ), |
|
77
|
|
|
[] |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
private function newRequest() { |
|
82
|
|
|
return new GetInTouchRequest( |
|
83
|
|
|
self::INQUIRER_FIRST_NAME, |
|
84
|
|
|
self::INQUIRER_LAST_NAME, |
|
85
|
|
|
self::INQUIRER_EMAIL_ADDRESS, |
|
86
|
|
|
self::INQUIRY_SUBJECT, |
|
87
|
|
|
self::INQUIRY_MESSAGE |
|
88
|
|
|
); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
private function newSucceedingValidator() { |
|
92
|
|
|
$validator = $this->getMockBuilder( GetInTouchValidator::class ) |
|
93
|
|
|
->disableOriginalConstructor() |
|
94
|
|
|
->getMock(); |
|
95
|
|
|
$validator->method( 'validate' )->willReturn( new ValidationResult() ); |
|
96
|
|
|
|
|
97
|
|
|
return $validator; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
|
101
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: