Passed
Push — main ( b7b8b7...5de84d )
by Gabriel
51s queued 15s
created

AddressChangeIdTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 18
c 2
b 0
f 0
dl 0
loc 41
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructorAcceptValidUuids() 0 5 1
A invalidUUIDProvider() 0 6 1
A testThrowsExceptionsWhenUUIDIsInvalid() 0 3 1
A testCanCheckEqualityWithStrings() 0 5 1
A testCanCheckEqualityWithOtherID() 0 6 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model;
6
7
use PHPUnit\Framework\TestCase;
8
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId;
9
10
/**
11
 * @covers \WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId
12
 */
13
class AddressChangeIdTest extends TestCase {
14
15
	public function testConstructorAcceptValidUuids(): void {
16
		$uuid = '72dfed91-fa40-4af0-9e80-c6010ab29cd1';
17
		$addressChangeId = AddressChangeId::fromString( $uuid );
18
19
		$this->assertSame( $uuid, $addressChangeId->__toString() );
20
	}
21
22
	/**
23
	 * @dataProvider invalidUUIDProvider
24
	 */
25
	public function testThrowsExceptionsWhenUUIDIsInvalid( string $invalidUUID ): void {
26
		$this->expectException( \InvalidArgumentException::class );
27
		AddressChangeId::fromString( $invalidUUID );
28
	}
29
30
	/**
31
	 * @return \Generator<string[]>
32
	 */
33
	public static function invalidUUIDProvider(): \Generator {
34
		yield [ '' ];
35
		yield [ 'just a string' ];
36
		yield [ '1111222233334444-1111222233334444-1111222233334444-1111222233334444-1111222233334444' ];
37
		yield [ 'e-f-f-e-d' ];
38
		yield [ 'This-is-not-a-UUID' ];
39
	}
40
41
	public function testCanCheckEqualityWithStrings(): void {
42
		$uuid = '72dfed91-fa40-4af0-9e80-c6010ab29cd1';
43
		$addressChangeId = AddressChangeId::fromString( $uuid );
44
45
		$this->assertTrue( $addressChangeId->equals( $uuid ), 'IDs should compare equals' );
46
	}
47
48
	public function testCanCheckEqualityWithOtherID(): void {
49
		$uuid = '72dfed91-fa40-4af0-9e80-c6010ab29cd1';
50
		$addressChangeId = AddressChangeId::fromString( $uuid );
51
		$addressChangeIdWithSameUUID = AddressChangeId::fromString( $uuid );
52
53
		$this->assertTrue( $addressChangeId->equals( $addressChangeIdWithSameUUID ), 'IDs should compare equals' );
54
	}
55
}
56