1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Pitchart\Phlunit\Checks; |
5
|
|
|
|
6
|
|
|
use PHPUnit\Framework\Assert; |
7
|
|
|
use Pitchart\Phlunit\Checks\Converter\ToDateTime; |
8
|
|
|
use Pitchart\Phlunit\Checks\Mixin\ConstraintCheck; |
9
|
|
|
use Pitchart\Phlunit\Checks\Mixin\TypeCheck; |
10
|
|
|
use Pitchart\Phlunit\Checks\Mixin\WithMessage; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class IntegerCheck |
14
|
|
|
* |
15
|
|
|
* @package Pitchart\Phlunit\Checks |
16
|
|
|
* |
17
|
|
|
* @author Julien VITTE <[email protected]> |
18
|
|
|
* |
19
|
|
|
* @implements FluentCheck<int> |
20
|
|
|
*/ |
21
|
|
|
class IntegerCheck implements FluentCheck |
22
|
|
|
{ |
23
|
1 |
|
use TypeCheck, ConstraintCheck, WithMessage; |
24
|
1 |
|
use ToDateTime { asDateTime as asDateTimeWithFormat; } |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var int |
28
|
|
|
*/ |
29
|
|
|
private $value; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* GenericCheck constructor. |
33
|
|
|
* |
34
|
|
|
* @param $value |
35
|
|
|
*/ |
36
|
11 |
|
public function __construct(int $value) |
37
|
|
|
{ |
38
|
11 |
|
$this->value = $value; |
39
|
11 |
|
} |
40
|
|
|
|
41
|
1 |
|
public function isEqualTo(int $expected): self |
42
|
|
|
{ |
43
|
1 |
|
Assert::assertSame($expected, $this->value, $this->message); |
44
|
1 |
|
$this->resetMessage(); |
45
|
1 |
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
1 |
|
public function isNotEqualTo(int $expected): self |
49
|
|
|
{ |
50
|
1 |
|
Assert::assertNotSame($expected, $this->value, $this->message); |
51
|
1 |
|
$this->resetMessage(); |
52
|
1 |
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
public function isEmpty(): self |
56
|
|
|
{ |
57
|
1 |
|
Assert::assertEmpty($this->value, $this->message); |
58
|
1 |
|
$this->resetMessage(); |
59
|
1 |
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
public function isNotEmpty(): self |
63
|
|
|
{ |
64
|
1 |
|
Assert::assertNotEmpty($this->value, $this->message); |
65
|
1 |
|
$this->resetMessage(); |
66
|
1 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
2 |
|
public function isGreaterThan(float $expected): self |
70
|
|
|
{ |
71
|
2 |
|
Assert::assertGreaterThan($expected, $this->value, $this->message); |
72
|
2 |
|
$this->resetMessage(); |
73
|
2 |
|
return $this; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function isGreaterThanOrEqualTo(float $expected): self |
77
|
|
|
{ |
78
|
1 |
|
Assert::assertGreaterThanOrEqual($expected, $this->value, $this->message); |
79
|
1 |
|
$this->resetMessage(); |
80
|
1 |
|
return $this; |
81
|
|
|
} |
82
|
|
|
|
83
|
2 |
|
public function isLessThan(float $expected): self |
84
|
|
|
{ |
85
|
2 |
|
Assert::assertLessThan($expected, $this->value, $this->message); |
86
|
2 |
|
$this->resetMessage(); |
87
|
2 |
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
public function isLessThanOrEqualTo(float $expected): self |
91
|
|
|
{ |
92
|
1 |
|
Assert::assertLessThanOrEqual($expected, $this->value, $this->message); |
93
|
1 |
|
$this->resetMessage(); |
94
|
1 |
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
public function asDateTime(string $format = 'Y-m-d H:i:s'): DateTimeCheck |
|
|
|
|
98
|
|
|
{ |
99
|
1 |
|
return $this->asDateTimeWithFormat('U'); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
} |
104
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.