1 | <?php declare(strict_types=1); |
||
2 | |||
3 | |||
4 | namespace Pitchart\Phlunit\Checks; |
||
5 | |||
6 | use PHPUnit\Framework\Assert; |
||
7 | use Pitchart\Phlunit\Checks\Mixin\ConstraintCheck; |
||
8 | use Pitchart\Phlunit\Checks\Mixin\FluentChecks; |
||
9 | use Pitchart\Phlunit\Checks\Mixin\TypeCheck; |
||
0 ignored issues
–
show
|
|||
10 | use Pitchart\Phlunit\Checks\Mixin\WithMessage; |
||
11 | |||
12 | class GenericCheck implements FluentCheck |
||
13 | { |
||
14 | 1 | use TypeCheck, FluentChecks, ConstraintCheck, WithMessage; |
|
15 | |||
16 | /** |
||
17 | * @var mixed |
||
18 | */ |
||
19 | private $value; |
||
20 | |||
21 | /** |
||
22 | * GenericCheck constructor. |
||
23 | * |
||
24 | * @param mixed $value |
||
25 | */ |
||
26 | 133 | public function __construct($value) |
|
27 | { |
||
28 | 133 | $this->value = $value; |
|
29 | 133 | } |
|
30 | |||
31 | /** |
||
32 | * @param mixed $expected |
||
33 | * |
||
34 | * @return GenericCheck |
||
35 | */ |
||
36 | 34 | public function isEqualTo($expected): self |
|
37 | { |
||
38 | 34 | Assert::assertSame($expected, $this->value, $this->message); |
|
39 | 34 | $this->resetMessage(); |
|
40 | 34 | return $this; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * @param mixed $expected |
||
45 | * |
||
46 | * @return GenericCheck |
||
47 | */ |
||
48 | 2 | public function isNotEqualTo($expected): self |
|
49 | { |
||
50 | 2 | Assert::assertNotEquals($expected, $this->value, $this->message); |
|
51 | 2 | $this->resetMessage(); |
|
52 | 2 | return $this; |
|
53 | } |
||
54 | |||
55 | 2 | public function isEmpty(): self |
|
56 | { |
||
57 | 2 | Assert::assertEmpty($this->value, $this->message); |
|
58 | 2 | $this->resetMessage(); |
|
59 | 2 | 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 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/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 beforeOtherDir/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: