Completed
Push — master ( 88699b...ae29c5 )
by Gabriel
13s
created

ShowApplicationConfirmationUseCaseTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\MembershipContext\Tests\Integration\UseCases\ShowApplicationConfirmation;
6
7
use PHPUnit\Framework\TestCase;
8
use WMDE\Fundraising\Frontend\MembershipContext\Authorization\ApplicationAuthorizer;
9
use WMDE\Fundraising\Frontend\MembershipContext\Domain\Model\Application;
10
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Data\ValidMembershipApplication;
11
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\FailingAuthorizer;
12
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\FakeApplicationRepository;
13
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\FixedApplicationTokenFetcher;
14
use WMDE\Fundraising\Frontend\MembershipContext\Tests\Fixtures\SucceedingAuthorizer;
15
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowApplicationConfirmation\ShowAppConfirmationRequest;
16
use WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowApplicationConfirmation\ShowApplicationConfirmationUseCase;
17
18
/**
19
 * @covers \WMDE\Fundraising\Frontend\MembershipContext\UseCases\ShowApplicationConfirmation\ShowApplicationConfirmationUseCase
20
 *
21
 * @license GNU GPL v2+
22
 * @author Jeroen De Dauw < [email protected] >
23
 */
24
class ShowApplicationConfirmationUseCaseTest extends TestCase {
25
26
	private const APPLICATION_ID = 42;
27
28
	/**
29
	 * @var FakeShowApplicationConfirmationPresenter
30
	 */
31
	private $presenter;
32
33
	/**
34
	 * @var ApplicationAuthorizer
35
	 */
36
	private $authorizer;
37
38
	/**
39
	 * @var FakeApplicationRepository
40
	 */
41
	private $repository;
42
43
	/**
44
	 * @var FixedApplicationTokenFetcher
45
	 */
46
	private $tokenFetcher;
47
48
	public function setUp() {
49
		$this->presenter = new FakeShowApplicationConfirmationPresenter();
50
		$this->authorizer = new SucceedingAuthorizer();
51
		$this->repository = new FakeApplicationRepository();
52
		$this->tokenFetcher = FixedApplicationTokenFetcher::newWithDefaultTokens();
0 ignored issues
show
Documentation Bug introduced by
It seems like \WMDE\Fundraising\Fronte...:newWithDefaultTokens() of type object<self> is incompatible with the declared type object<WMDE\Fundraising\...pplicationTokenFetcher> of property $tokenFetcher.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
53
54
		$this->repository->storeApplication( $this->newApplication() );
55
	}
56
57
	private function newApplication(): Application {
58
		$application = ValidMembershipApplication::newDomainEntity();
59
60
		$application->assignId( self::APPLICATION_ID );
61
62
		return $application;
63
	}
64
65
	private function invokeUseCaseWithCorrectRequestModel() {
66
		$request = new ShowAppConfirmationRequest( self::APPLICATION_ID );
67
		$this->newUseCase()->showConfirmation( $request );
68
	}
69
70
	private function newUseCase(): ShowApplicationConfirmationUseCase {
71
		return new ShowApplicationConfirmationUseCase(
72
			$this->presenter,
73
			$this->authorizer,
74
			$this->repository,
75
			$this->tokenFetcher
76
		);
77
	}
78
79
	public function testHappyPath_successResponseWithApplicationIsReturned() {
80
		$this->invokeUseCaseWithCorrectRequestModel();
81
82
		$this->assertSame(
83
			self::APPLICATION_ID,
84
			$this->presenter->getShownApplication()->getId()
85
		);
86
87
		$this->assertSame(
88
			FixedApplicationTokenFetcher::UPDATE_TOKEN,
89
			$this->presenter->getShownUpdateToken()
90
		);
91
	}
92
93
	public function testWhenRepositoryThrowsAnonymizedException_anonymizedMessageIsPresented() {
94
		$this->repository->throwAnonymizedOnRead();
95
96
		$this->invokeUseCaseWithCorrectRequestModel();
97
98
		$this->assertTrue( $this->presenter->anonymizedResponseWasShown() );
99
	}
100
101
	public function testWhenAuthorizerReturnsFalse_accessViolationIsPresented() {
102
		$this->authorizer = new FailingAuthorizer();
103
104
		$this->invokeUseCaseWithCorrectRequestModel();
105
106
		$this->assertTrue( $this->presenter->accessViolationWasShown() );
107
	}
108
109
	public function testWhenRepositoryThrowsException_technicalErrorIsPresented() {
110
		$this->repository->throwOnRead();
111
112
		$this->invokeUseCaseWithCorrectRequestModel();
113
114
		$this->assertSame( 'A database error occurred', $this->presenter->getShownTechnicalError() );
115
	}
116
117
}
118