Completed
Push — master ( 2627d9...865111 )
by Gabriel
10s
created

testGetCentsReturnsConstructorArgument()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
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