EuroErisTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGivenNegativeAmount_constructorThrowsException() 0 7 1
A testGetCentsReturnsConstructorArgument() 0 8 1
A testEquality() 0 8 1
A testNewFromString() 0 15 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Euro\Tests\Unit;
6
7
use Eris\Generator;
8
use Eris\TestTrait;
9
use PHPUnit\Framework\TestCase;
10
use WMDE\Euro\Euro;
11
12
/**
13
 * @covers \WMDE\Euro\Euro
14
 *
15
 * @license GNU GPL v2+
16
 * @author Jeroen De Dauw < [email protected] >
17
 */
18
class EuroErisTest extends TestCase {
19
	use TestTrait;
20
21
	public function testGivenNegativeAmount_constructorThrowsException() {
22
		$this->forAll( Generator\neg() )
23
			->then( function( int $negativeInteger ) {
24
				$this->expectException( \InvalidArgumentException::class );
25
				Euro::newFromCents( $negativeInteger );
26
			} );
27
	}
28
29
	public function testGetCentsReturnsConstructorArgument() {
30
		$this->limitTo( 10000 )
31
			->forAll( Generator\choose( 0, 100 * 100 ) )
32
			->then( function( int $unsignedInteger ) {
33
				$amount = Euro::newFromCents( $unsignedInteger );
34
				$this->assertSame( $unsignedInteger, $amount->getEuroCents() );
35
			} );
36
	}
37
38
	public function testEquality() {
39
		$this->limitTo( 10000 )
40
			->forAll( Generator\choose( 0, 100 * 100 ) )
41
			->then( function( int $unsignedInteger ) {
42
				$amount = Euro::newFromCents( $unsignedInteger );
43
				$this->assertTrue( $amount->equals( Euro::newFromCents( $unsignedInteger ) ) );
44
			} );
45
	}
46
47
	public function testNewFromString() {
48
		$this->limitTo( 10000 )
49
			->forAll( Generator\choose( 0, 100 ), Generator\choose( 0, 99 ) )
50
			->then( function( int $firstInt, int $secondInt ) {
51
				$euroString =
52
					(string)$firstInt
53
					. '.'
54
					. str_pad( (string)$secondInt, 2, '0', STR_PAD_LEFT );
55
56
				$this->assertSame(
57
					$firstInt * 100 + $secondInt,
58
					Euro::newFromString( $euroString )->getEuroCents()
59
				);
60
			} );
61
	}
62
63
}
64