Issues (26)

src/Checks/IntegerCheck.php (1 issue)

Labels
Severity
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\FluentChecks;
10
use Pitchart\Phlunit\Checks\Mixin\TypeCheck;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Pitchart\Phlunit\Checks\TypeCheck. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
use Pitchart\Phlunit\Checks\Mixin\WithMessage;
12
13
/**
14
 * Class IntegerCheck
15
 *
16
 * @package Pitchart\Phlunit\Checks
17
 *
18
 * @author Julien VITTE <[email protected]>
19
 *
20
 * @implements FluentCheck<int>
21
 */
22
class IntegerCheck implements FluentCheck
23
{
24 1
    use TypeCheck, FluentChecks, ConstraintCheck, WithMessage;
25 1
    use ToDateTime { asDateTime as asDateTimeWithFormat; }
26
27
    /**
28
     * @var int
29
     */
30
    private $value;
31
32
    /**
33
     * GenericCheck constructor.
34
     *
35
     * @param $value
36
     */
37 15
    public function __construct(int $value)
38
    {
39 15
        $this->value = $value;
40 15
    }
41
42 1
    public function isEqualTo(int $expected): self
43
    {
44 1
        Assert::assertSame($expected, $this->value, $this->message);
45 1
        $this->resetMessage();
46 1
        return $this;
47
    }
48
49 1
    public function isNotEqualTo(int $expected): self
50
    {
51 1
        Assert::assertNotSame($expected, $this->value, $this->message);
52 1
        $this->resetMessage();
53 1
        return $this;
54
    }
55
56 1
    public function isEmpty(): self
57
    {
58 1
        Assert::assertEmpty($this->value, $this->message);
59 1
        $this->resetMessage();
60 1
        return $this;
61
    }
62
63 1
    public function isNotEmpty(): self
64
    {
65 1
        Assert::assertNotEmpty($this->value, $this->message);
66 1
        $this->resetMessage();
67 1
        return $this;
68
    }
69
70 2
    public function isGreaterThan(float $expected): self
71
    {
72 2
        Assert::assertGreaterThan($expected, $this->value, $this->message);
73 2
        $this->resetMessage();
74 2
        return $this;
75
    }
76
77 1
    public function isGreaterThanOrEqualTo(float $expected): self
78
    {
79 1
        Assert::assertGreaterThanOrEqual($expected, $this->value, $this->message);
80 1
        $this->resetMessage();
81 1
        return $this;
82
    }
83
84 2
    public function isLessThan(float $expected): self
85
    {
86 2
        Assert::assertLessThan($expected, $this->value, $this->message);
87 2
        $this->resetMessage();
88 2
        return $this;
89
    }
90
91 1
    public function isLessThanOrEqualTo(float $expected): self
92
    {
93 1
        Assert::assertLessThanOrEqual($expected, $this->value, $this->message);
94 1
        $this->resetMessage();
95 1
        return $this;
96
    }
97
98 1
    public function asDateTime(): DateTimeCheck
99
    {
100 1
        return $this->asDateTimeWithFormat('U');
101
    }
102
}
103