|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Pitchart\Phlunit\Checks; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\Assert; |
|
6
|
|
|
use Pitchart\Phlunit\Checks\Mixin\TypeCheck; |
|
7
|
|
|
use Pitchart\Phlunit\Checks\Mixin\WithMessage; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class FloatCheck |
|
11
|
|
|
* |
|
12
|
|
|
* @package Pitchart\Phlunit\Checks |
|
13
|
|
|
* |
|
14
|
|
|
* @author Julien VITTE <[email protected]> |
|
15
|
|
|
* |
|
16
|
|
|
* @implements FluentCheck<double> |
|
17
|
|
|
*/ |
|
18
|
|
|
class FloatCheck implements FluentCheck |
|
19
|
|
|
{ |
|
20
|
1 |
|
use WithMessage, TypeCheck; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var float |
|
24
|
|
|
*/ |
|
25
|
|
|
private $value; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var |
|
29
|
|
|
*/ |
|
30
|
|
|
private $delta; |
|
31
|
|
|
|
|
32
|
8 |
|
public function __construct(float $value) |
|
33
|
|
|
{ |
|
34
|
8 |
|
$this->value = $value; |
|
35
|
8 |
|
} |
|
36
|
|
|
|
|
37
|
2 |
|
public function isEqualTo(float $expected): self |
|
38
|
|
|
{ |
|
39
|
2 |
|
if ($this->delta) { |
|
40
|
1 |
|
Assert::assertEqualsWithDelta($expected, $this->value, $this->delta, $this->message); |
|
41
|
|
|
} else { |
|
42
|
1 |
|
Assert::assertSame($expected, $this->value, $this->message); |
|
43
|
|
|
} |
|
44
|
2 |
|
$this->resetMessage(); |
|
45
|
2 |
|
return $this; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
2 |
|
public function isNotEqualTo(float $expected): self |
|
49
|
|
|
{ |
|
50
|
2 |
|
if ($this->delta) { |
|
51
|
1 |
|
Assert::assertNotEqualsWithDelta($expected, $this->value, $this->delta, $this->message); |
|
52
|
|
|
} else { |
|
53
|
2 |
|
Assert::assertNotSame($expected, $this->value, $this->message); |
|
54
|
|
|
} |
|
55
|
2 |
|
$this->resetMessage(); |
|
56
|
2 |
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
1 |
|
public function isEmpty(): self |
|
60
|
|
|
{ |
|
61
|
1 |
|
Assert::assertEmpty($this->value, $this->message); |
|
62
|
1 |
|
$this->resetMessage(); |
|
63
|
1 |
|
return $this; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
1 |
|
public function isNotEmpty(): self |
|
67
|
|
|
{ |
|
68
|
1 |
|
Assert::assertNotEmpty($this->value, $this->message); |
|
69
|
1 |
|
$this->resetMessage(); |
|
70
|
1 |
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
public function isGreaterThan(float $expected): self |
|
74
|
|
|
{ |
|
75
|
1 |
|
Assert::assertGreaterThan($expected, $this->value, $this->message); |
|
76
|
1 |
|
$this->resetMessage(); |
|
77
|
1 |
|
return $this; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
public function isGreaterThanOrEqualTo(float $expected): self |
|
81
|
|
|
{ |
|
82
|
1 |
|
Assert::assertGreaterThanOrEqual($expected, $this->value, $this->message); |
|
83
|
1 |
|
$this->resetMessage(); |
|
84
|
1 |
|
return $this; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
1 |
|
public function isLessThan(float $expected): self |
|
88
|
|
|
{ |
|
89
|
1 |
|
Assert::assertLessThan($expected, $this->value, $this->message); |
|
90
|
1 |
|
$this->resetMessage(); |
|
91
|
1 |
|
return $this; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
public function isLessThanOrEqualTo(float $expected): self |
|
95
|
|
|
{ |
|
96
|
1 |
|
Assert::assertLessThanOrEqual($expected, $this->value, $this->message); |
|
97
|
1 |
|
$this->resetMessage(); |
|
98
|
1 |
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
1 |
|
public function withDelta(float $delta) |
|
102
|
|
|
{ |
|
103
|
1 |
|
$this->delta = $delta; |
|
104
|
1 |
|
return $this; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
1 |
|
public function strictly() |
|
108
|
|
|
{ |
|
109
|
1 |
|
return $this->withDelta(0.0); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|