testConstructorAcceptValidUuids()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\AddressChangeContext\Tests\Unit\Domain\Model;
6
7
use PHPUnit\Framework\Attributes\CoversClass;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\CoversClass was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use PHPUnit\Framework\Attributes\DataProvider;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\Attributes\DataProvider was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use PHPUnit\Framework\TestCase;
10
use WMDE\Fundraising\AddressChangeContext\Domain\Model\AddressChangeId;
11
12
#[CoversClass( AddressChangeId::class )]
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
	#[DataProvider( 'invalidUUIDProvider' )]
23
	public function testThrowsExceptionsWhenUUIDIsInvalid( string $invalidUUID ): void {
24
		$this->expectException( \InvalidArgumentException::class );
25
		AddressChangeId::fromString( $invalidUUID );
26
	}
27
28
	/**
29
	 * @return \Generator<string[]>
30
	 */
31
	public static function invalidUUIDProvider(): \Generator {
32
		yield [ '' ];
33
		yield [ 'just a string' ];
34
		yield [ '1111222233334444-1111222233334444-1111222233334444-1111222233334444-1111222233334444' ];
35
		yield [ 'e-f-f-e-d' ];
36
		yield [ 'This-is-not-a-UUID' ];
37
	}
38
39
	public function testCanCheckEqualityWithStrings(): void {
40
		$uuid = '72dfed91-fa40-4af0-9e80-c6010ab29cd1';
41
		$addressChangeId = AddressChangeId::fromString( $uuid );
42
43
		$this->assertTrue( $addressChangeId->equals( $uuid ), 'IDs should compare equals' );
44
	}
45
46
	public function testCanCheckEqualityWithOtherID(): void {
47
		$uuid = '72dfed91-fa40-4af0-9e80-c6010ab29cd1';
48
		$addressChangeId = AddressChangeId::fromString( $uuid );
49
		$addressChangeIdWithSameUUID = AddressChangeId::fromString( $uuid );
50
51
		$this->assertTrue( $addressChangeId->equals( $addressChangeIdWithSameUUID ), 'IDs should compare equals' );
52
	}
53
}
54