| 1 | <?php |
||
| 2 | |||
| 3 | declare( strict_types = 1 ); |
||
| 4 | |||
| 5 | namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\UseCases; |
||
| 6 | |||
| 7 | use PHPUnit\Framework\Attributes\CoversClass; |
||
|
0 ignored issues
–
show
|
|||
| 8 | use PHPUnit\Framework\TestCase; |
||
| 9 | use WMDE\Fundraising\AddressChangeContext\Domain\AddressChangeRepository; |
||
| 10 | use WMDE\Fundraising\AddressChangeContext\Domain\Model\Address; |
||
| 11 | use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChange; |
||
| 12 | use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId; |
||
| 13 | use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressType; |
||
| 14 | use WMDE\Fundraising\AddressChangeContext\UseCases\ReadAddressChange\AddressChangeData; |
||
| 15 | use WMDE\Fundraising\AddressChangeContext\UseCases\ReadAddressChange\ReadAddressChangeUseCase; |
||
| 16 | |||
| 17 | #[CoversClass( ReadAddressChangeUseCase::class )] |
||
| 18 | #[CoversClass( AddressChangeData::class )] |
||
| 19 | class ReadAddressChangeUseCaseTest extends TestCase { |
||
| 20 | |||
| 21 | private const VALID_UUID = '2a54c0a1-fc94-4ef8-8b0a-7c2ed8565521'; |
||
| 22 | private const UPDATE_UUID = 'c52258ba-fed1-476a-a7e5-c721df087c12'; |
||
| 23 | private const INVALID_UUID = 'NOT A VALID UUID'; |
||
| 24 | private const DUMMY_DONATION_ID = 0; |
||
| 25 | |||
| 26 | public function testGivenValidUuid_returnsAddressChangeData(): void { |
||
| 27 | $mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
||
| 28 | $mockAddressChangeRepository->method( 'getAddressChangeByUuids' )->willReturn( |
||
| 29 | $this->createUsedAddressChange() |
||
| 30 | ); |
||
| 31 | |||
| 32 | $readAddressUseCase = new ReadAddressChangeUseCase( $mockAddressChangeRepository ); |
||
| 33 | $expectedAddress = [ |
||
| 34 | 'salutation' => 'Herr', |
||
| 35 | 'company' => '', |
||
| 36 | 'title' => 'Prof. Dr.', |
||
| 37 | 'firstName' => 'Test', |
||
| 38 | 'lastName' => 'User', |
||
| 39 | 'street' => 'Teststreet 12345', |
||
| 40 | 'postcode' => '98765', |
||
| 41 | 'city' => 'Berlin', |
||
| 42 | 'country' => 'Germany', |
||
| 43 | 'isPersonalAddress' => true, |
||
| 44 | 'isCompanyAddress' => false, |
||
| 45 | ]; |
||
| 46 | |||
| 47 | $addressChangeData = $readAddressUseCase->getAddressChangeByUuids( self::VALID_UUID, self::VALID_UUID ); |
||
| 48 | |||
| 49 | $this->assertNotNull( $addressChangeData ); |
||
| 50 | $this->assertEquals( self::UPDATE_UUID, $addressChangeData->identifier ); |
||
| 51 | $this->assertEquals( self::VALID_UUID, $addressChangeData->previousIdentifier ); |
||
| 52 | $this->assertEquals( $expectedAddress, $addressChangeData->address ); |
||
| 53 | $this->assertTrue( $addressChangeData->donationReceipt ); |
||
| 54 | $this->assertEquals( AddressChange::EXPORT_STATE_USED_NOT_EXPORTED, $addressChangeData->exportState ); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function testGivenValidUuidForUnusedAddressChange_returnsAddressChangeData(): void { |
||
| 58 | $mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
||
| 59 | $mockAddressChangeRepository->method( 'getAddressChangeByUuids' )->willReturn( |
||
| 60 | $this->createUnusedAddressChange() |
||
| 61 | ); |
||
| 62 | |||
| 63 | $readAddressUseCase = new ReadAddressChangeUseCase( $mockAddressChangeRepository ); |
||
| 64 | |||
| 65 | $addressChangeData = $readAddressUseCase->getAddressChangeByUuids( self::VALID_UUID, self::VALID_UUID ); |
||
| 66 | |||
| 67 | $this->assertNotNull( $addressChangeData ); |
||
| 68 | $this->assertEquals( self::VALID_UUID, $addressChangeData->identifier ); |
||
| 69 | $this->assertEquals( self::VALID_UUID, $addressChangeData->previousIdentifier ); |
||
| 70 | $this->assertEquals( [], $addressChangeData->address ); |
||
| 71 | $this->assertTrue( $addressChangeData->donationReceipt ); |
||
| 72 | $this->assertEquals( AddressChange::EXPORT_STATE_NO_DATA, $addressChangeData->exportState ); |
||
| 73 | } |
||
| 74 | |||
| 75 | public function testGivenInvalidDonationUuids_returnsNull(): void { |
||
| 76 | $mockAddressChangeRepository = $this->createMock( AddressChangeRepository::class ); |
||
| 77 | $mockAddressChangeRepository->method( 'getAddressChangeByUuids' )->willReturn( null ); |
||
| 78 | |||
| 79 | $readAddressUseCase = new ReadAddressChangeUseCase( $mockAddressChangeRepository ); |
||
| 80 | |||
| 81 | $this->assertNull( $readAddressUseCase->getAddressChangeByUuids( self::INVALID_UUID, self::INVALID_UUID ) ); |
||
| 82 | } |
||
| 83 | |||
| 84 | private function createUnusedAddressChange(): AddressChange { |
||
| 85 | return new AddressChange( |
||
| 86 | AddressType::Person, |
||
| 87 | AddressChange::EXTERNAL_ID_TYPE_DONATION, |
||
| 88 | self::DUMMY_DONATION_ID, |
||
| 89 | AddressChangeId::fromString( self::VALID_UUID ) |
||
| 90 | ); |
||
| 91 | } |
||
| 92 | |||
| 93 | private function createUsedAddressChange(): AddressChange { |
||
| 94 | $addressChange = new AddressChange( |
||
| 95 | AddressType::Person, |
||
| 96 | AddressChange::EXTERNAL_ID_TYPE_DONATION, |
||
| 97 | self::DUMMY_DONATION_ID, |
||
| 98 | AddressChangeId::fromString( self::VALID_UUID ) |
||
| 99 | ); |
||
| 100 | |||
| 101 | $addressChange->performAddressChange( |
||
| 102 | $this->newPersonalAddress(), |
||
| 103 | AddressChangeId::fromString( self::UPDATE_UUID ) |
||
| 104 | ); |
||
| 105 | |||
| 106 | return $addressChange; |
||
| 107 | } |
||
| 108 | |||
| 109 | private function newPersonalAddress(): Address { |
||
| 110 | return Address::newPersonalAddress( |
||
| 111 | 'Herr', |
||
| 112 | 'Prof. Dr.', |
||
| 113 | 'Test', |
||
| 114 | 'User', |
||
| 115 | 'Teststreet 12345', |
||
| 116 | '98765', |
||
| 117 | 'Berlin', |
||
| 118 | 'Germany' |
||
| 119 | ); |
||
| 120 | } |
||
| 121 | } |
||
| 122 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths