Completed
Pull Request — master (#1)
by Tim
79:06 queued 13:58
created

newChangeAddressRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 0
dl 0
loc 14
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\UseCases;
6
7
use PHPUnit\Framework\TestCase;
8
use WMDE\Fundraising\AddressChange\Domain\AddressChangeRepository;
9
use WMDE\Fundraising\AddressChange\Domain\Model\AddressChange;
10
use WMDE\Fundraising\AddressChange\UseCases\ChangeAddress\ChangeAddressRequest;
11
use WMDE\Fundraising\AddressChange\UseCases\ChangeAddress\ChangeAddressUseCase;
12
13
/**
14
 * @covers \WMDE\Fundraising\AddressChange\UseCases\ChangeAddress\ChangeAddressUseCase
15
 */
16
class ChangeAddressUseCaseTest extends TestCase {
17
18
	private const VALID_SAMPLE_UUID = 'd8441c6e-1f7a-4710-97d3-0e2126c86d40';
19
	private const INVALID_SAMPLE_UUID = 'd8441c6e-1f7a-4710-97d3-0e2126c86d41';
20
21
	public function testGivenValidAddressChangeRequest_successResponseIsReturned(): void {
22
		$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class );
23
		$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn(
0 ignored issues
show
Bug introduced by
The method method() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
		$mockAddressChangeRepository->/** @scrutinizer ignore-call */ 
24
                                method( 'getAddressChangeByUuid' )->willReturn(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
24
			AddressChange::createNewPersonAddressChange( self::VALID_SAMPLE_UUID )
25
		);
26
		$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository );
27
		$response = $useCase->changeAddress( $this->newChangeAddressRequest() );
28
		$this->assertTrue( $response->isSuccess() );
29
	}
30
31
	public function testGivenInvalidAddressChangeRequest_errorResponseIsReturned(): void {
32
		$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class );
33
		$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn(
34
			AddressChange::createNewPersonAddressChange( self::VALID_SAMPLE_UUID )
35
		);
36
		$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository );
37
		$response = $useCase->changeAddress( $this->newMissingDataChangeAddressRequest() );
38
		$this->assertFalse( $response->isSuccess() );
39
	}
40
41
	public function testGivenUnknownAddressChangeRequestIdentifier_errorResponseIsReturned(): void {
42
		$mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class );
43
		$mockAddressChangeRepository->method( 'getAddressChangeByUuid' )->willReturn(
44
			null
45
		);
46
		$useCase = new ChangeAddressUseCase( $mockAddressChangeRepository );
47
		$response = $useCase->changeAddress( $this->newChangeAddressRequest() );
48
		$this->assertFalse( $response->isSuccess() );
49
	}
50
51
	private function newChangeAddressRequest(): ChangeAddressRequest {
52
		$request = new ChangeAddressRequest();
53
		$request->setIdentifier( self::VALID_SAMPLE_UUID );
54
		$request->setAddress( 'Test' );
55
		$request->setAddressType( AddressChange::ADDRESS_TYPE_PERSON );
56
		$request->setCity( 'Test City' );
57
		$request->setCountry( 'Test Country' );
58
		$request->setFirstName( 'Test Name' );
59
		$request->setLastName( 'Test Last Name' );
60
		$request->setPostcode( '12345' );
61
		$request->setSalutation( 'Herr' );
62
		$request->setTitle( 'Prof. Dr.' );
63
		$request->freeze();
64
		return $request;
65
	}
66
67
	private function newMissingDataChangeAddressRequest(): ChangeAddressRequest {
68
		$request = new ChangeAddressRequest();
69
		$request->setIdentifier( self::VALID_SAMPLE_UUID );
70
		$request->setAddress( 'Test' );
71
		$request->setAddressType( AddressChange::ADDRESS_TYPE_PERSON );
72
		$request->setCity( '' );
73
		$request->setCountry( 'Test Country' );
74
		$request->setFirstName( 'Test Name' );
75
		$request->setLastName( 'Test Last Name' );
76
		$request->setPostcode( '12345' );
77
		$request->setSalutation( 'Herr' );
78
		$request->setTitle( 'Prof. Dr.' );
79
		$request->freeze();
80
		return $request;
81
	}
82
}
83