Passed
Push — master ( 3c05f7...479341 )
by Mr
07:34
created

IntValueTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 95.56%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 31
c 2
b 0
f 0
dl 0
loc 68
ccs 43
cts 45
cp 0.9556
rs 10
wmc 9

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testToNative() 0 4 1
A setUp() 0 3 1
A testFromNative() 0 6 1
A testAdd() 0 6 1
A testZero() 0 5 1
A testMakeEmpty() 0 6 1
A testToString() 0 4 1
A testSubtract() 0 6 1
A testEquals() 0 6 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/value-object project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Tests\ValueObject;
10
11
use Daikon\Interop\InvalidArgumentException;
12
use Daikon\ValueObject\IntValue;
13
use PHPUnit\Framework\TestCase;
14
15
final class IntValueTest extends TestCase
16
{
17
    private const FIXED_NUM = 23;
18
19
    private IntValue $integer;
20
    
21 1
    public function testToNative(): void
22
    {
23 1
        $this->assertEquals(self::FIXED_NUM, $this->integer->toNative());
24 1
        $this->assertNull(IntValue::fromNative(null)->toNative());
25 1
    }
26
27 1
    public function testFromNative(): void
28
    {
29 1
        $this->assertEquals(null, IntValue::fromNative(null)->toNative());
30 1
        $this->assertEquals(null, IntValue::fromNative('')->toNative());
31 1
        $this->assertEquals(0, IntValue::fromNative('0')->toNative());
32 1
        $this->assertEquals(-1, IntValue::fromNative(-1)->toNative());
33 1
    }
34
35 1
    public function testMakeEmpty(): void
36
    {
37 1
        $empty = IntValue::makeEmpty();
38 1
        $this->assertNull($empty->toNative());
39 1
        $this->assertEquals('', (string)$empty);
40 1
        $this->assertTrue($empty->isEmpty());
41 1
    }
42
43 1
    public function testZero(): void
44
    {
45 1
        $zero = IntValue::zero();
46 1
        $this->assertEquals(0, $zero->toNative());
47 1
        $this->assertEquals('0', (string)$zero);
48 1
    }
49
50 1
    public function testEquals(): void
51
    {
52 1
        $sameNumber = IntValue::fromNative(self::FIXED_NUM);
53 1
        $this->assertTrue($this->integer->equals($sameNumber));
54 1
        $differentNumber = IntValue::fromNative(42);
55 1
        $this->assertFalse($this->integer->equals($differentNumber));
56 1
    }
57
58 1
    public function testAdd(): void
59
    {
60 1
        $amount = IntValue::fromNative(10);
61 1
        $this->assertEquals(33, $this->integer->add($amount)->toNative());
62 1
        $this->expectException(InvalidArgumentException::class);
63 1
        $amount->add(IntValue::makeEmpty());
64
    }
65
66 1
    public function testSubtract(): void
67
    {
68 1
        $amount = IntValue::fromNative(10);
69 1
        $this->assertEquals(13, $this->integer->subtract($amount)->toNative());
70 1
        $this->expectException(InvalidArgumentException::class);
71 1
        $amount->subtract(IntValue::makeEmpty());
72
    }
73
74 1
    public function testToString(): void
75
    {
76 1
        $this->assertEquals((string)self::FIXED_NUM, (string)$this->integer);
77 1
        $this->assertEquals('', (string)IntValue::makeEmpty());
78 1
    }
79
80 8
    protected function setUp(): void
81
    {
82 8
        $this->integer = IntValue::fromNative(self::FIXED_NUM);
83 8
    }
84
}
85