testWhenSettingAllValues_assertNoNullFieldsDoesNothing()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\FreezableValueObject\Tests\Unit;
6
7
use RuntimeException;
8
9
/**
10
 * @covers \WMDE\FreezableValueObject\FreezableValueObject
11
 * @covers \WMDE\FreezableValueObject\Tests\Unit\FrozenValueObject
12
 *
13
 * @license GPL-2.0-or-later
14
 * @author Jeroen De Dauw < [email protected] >
15
 */
16
class FreezableValueObjectTest extends \PHPUnit\Framework\TestCase {
17
18
	public function testCanSetAndGetValuesBeforeFreeze(): void {
19
		$object = new FrozenValueObject();
20
21
		$object->setHeaderContent( 'header' );
22
		$object->setMainContent( 'body' );
23
		$object->setFooterContent( 'footer' );
24
25
		$this->assertSame( 'header', $object->getHeaderContent() );
26
		$this->assertSame( 'body', $object->getMainContent() );
27
		$this->assertSame( 'footer', $object->getFooterContent() );
28
	}
29
30
	public function testCanBeforeFreezeAndGetValuesAfter(): void {
31
		$object = new FrozenValueObject();
32
33
		$object->setHeaderContent( 'header' );
34
		$object->setMainContent( 'body' );
35
		$object->setFooterContent( 'footer' );
36
37
		$object->freeze();
38
39
		$this->assertSame( 'header', $object->getHeaderContent() );
40
		$this->assertSame( 'body', $object->getMainContent() );
41
		$this->assertSame( 'footer', $object->getFooterContent() );
42
	}
43
44
	public function testWhenFreezing_settersCauseException(): void {
45
		$object = new FrozenValueObject();
46
47
		$object->setHeaderContent( 'header' );
48
		$object->setMainContent( 'body' );
49
		$object->setFooterContent( 'footer' );
50
51
		$object->freeze();
52
53
		$this->expectException( RuntimeException::class );
54
		$this->expectExceptionMessage( 'Cannot write to a frozen object!' );
55
		$object->setHeaderContent( 'header' );
56
	}
57
58
	public function testWhenFreezingAndValueNotSet_settersCauseException(): void {
59
		$object = new FrozenValueObject();
60
61
		$object->freeze();
62
63
		$this->expectException( RuntimeException::class );
64
		$this->expectExceptionMessage( 'Cannot write to a frozen object!' );
65
		$object->setHeaderContent( 'header' );
66
	}
67
68
	public function testWhenNoValuesAreSet_assertNoNullFieldsThrowsException(): void {
69
		$object = new FrozenValueObject();
70
71
		$this->expectException( RuntimeException::class );
72
		$this->expectExceptionMessageRegExp( '/Field \'[a-zA-Z]+\' cannot be null/' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\TestCa...xceptionMessageRegExp() has been deprecated with message: Use expectExceptionMessageMatches() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
73
		$object->assertNoNullFields();
74
	}
75
76
	public function testWhenSettingAllValues_assertNoNullFieldsDoesNothing(): void {
77
		$object = new FrozenValueObject();
78
79
		$object->setHeaderContent( 'header' );
80
		$object->setMainContent( 'body' );
81
		$object->setFooterContent( 'footer' );
82
		$object->freeze();
83
84
		$object->assertNoNullFields();
85
		$this->assertTrue( true );
86
	}
87
88
}
89