Werkspot /
Enum
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Werkspot\Enum\Tests; |
||
| 6 | |||
| 7 | use PHPUnit\Framework\TestCase; |
||
| 8 | |||
| 9 | final class AbstractEnumTest extends TestCase |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @test |
||
| 13 | */ |
||
| 14 | public function enum(): void |
||
| 15 | { |
||
| 16 | $a = TestEnum::get(TestEnum::A); |
||
| 17 | $b = TestEnum::get(TestEnum::B); |
||
| 18 | |||
| 19 | self::assertSame(TestEnum::A, $a->getValue()); |
||
| 20 | self::assertSame(TestEnum::B, $b->getValue()); |
||
| 21 | self::assertSame(TestEnum::A, (string) $a); |
||
| 22 | self::assertSame(TestEnum::B, (string) $b); |
||
| 23 | } |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @test |
||
| 27 | */ |
||
| 28 | public function null(): void |
||
| 29 | { |
||
| 30 | $nullEnum = TestEnum::get(null); |
||
| 31 | self::assertNull($nullEnum->getValue()); |
||
| 32 | self::assertSame('', (string) $nullEnum); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @test |
||
| 37 | */ |
||
| 38 | public function integer(): void |
||
| 39 | { |
||
| 40 | $integerEnum = TestEnum::get(3); |
||
| 41 | self::assertSame(3, $integerEnum->getValue()); |
||
| 42 | self::assertSame('3', (string) $integerEnum); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @test |
||
| 47 | */ |
||
| 48 | public function equalsShouldReturnTrueWhenComparingObjectsWithTheSameTypeAndValue(): void |
||
| 49 | { |
||
| 50 | $a = TestEnum::get(TestEnum::A); |
||
| 51 | |||
| 52 | self::assertTrue($a->equals(TestEnum::get(TestEnum::A))); |
||
|
1 ignored issue
–
show
|
|||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @test |
||
| 57 | */ |
||
| 58 | public function equalsShouldReturnFalseWhenComparingObjectsWithTheSameTypeButDifferentValue(): void |
||
| 59 | { |
||
| 60 | $a = TestEnum::get(TestEnum::A); |
||
| 61 | |||
| 62 | self::assertFalse($a->equals(TestEnum::get(TestEnum::B))); |
||
|
1 ignored issue
–
show
\Werkspot\Enum\Tests\Tes...Enum\Tests\TestEnum::B) is of type object<Werkspot\Enum\Tests\TestEnum>, but the function expects a object<self>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @test |
||
| 67 | */ |
||
| 68 | public function equalsShouldReturnFalseWhenComparingObjectsWithTheSameValueButDifferentType(): void |
||
| 69 | { |
||
| 70 | $a = TestEnum::get(TestEnum::A); |
||
| 71 | |||
| 72 | self::assertFalse($a->equals(Test2Enum::get(Test2Enum::A))); |
||
|
1 ignored issue
–
show
\Werkspot\Enum\Tests\Tes...num\Tests\Test2Enum::A) is of type object<Werkspot\Enum\Tests\Test2Enum>, but the function expects a object<self>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @test |
||
| 77 | */ |
||
| 78 | public function equalsShouldReturnTrueWhenComparingObjectsWithDifferentTypeAndValue(): void |
||
| 79 | { |
||
| 80 | $a = TestEnum::get(TestEnum::A); |
||
| 81 | |||
| 82 | self::assertFalse($a->equals(Test2Enum::get(Test2Enum::C))); |
||
|
1 ignored issue
–
show
\Werkspot\Enum\Tests\Tes...num\Tests\Test2Enum::C) is of type object<Werkspot\Enum\Tests\Test2Enum>, but the function expects a object<self>.
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @test |
||
| 87 | * |
||
| 88 | * @expectedException \InvalidArgumentException |
||
| 89 | * @expectedExceptionMessage Value [anything] is not matching any valid value of class "TestEnum". Valid values are ['A', 'BEE', 1, 3, NULL, true]. |
||
| 90 | */ |
||
| 91 | public function exceptionMessage(): void |
||
| 92 | { |
||
| 93 | TestEnum::get('anything'); |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @test |
||
| 98 | * |
||
| 99 | * @dataProvider getInvertedCaseOptions |
||
| 100 | * @expectedException \InvalidArgumentException |
||
| 101 | * |
||
| 102 | * @param mixed $option |
||
| 103 | */ |
||
| 104 | public function getWithInvertedCaseIsIncorrect($option): void |
||
| 105 | { |
||
| 106 | TestEnum::get($option); |
||
| 107 | } |
||
| 108 | |||
| 109 | public function getInvertedCaseOptions() |
||
| 110 | { |
||
| 111 | return [ |
||
| 112 | [strtolower(TestEnum::A)], |
||
| 113 | [strtolower(TestEnum::B)], |
||
| 114 | ]; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @test |
||
| 119 | * |
||
| 120 | * @expectedException \InvalidArgumentException |
||
| 121 | */ |
||
| 122 | public function getWithStrictEqualMatchThrowsException(): void |
||
| 123 | { |
||
| 124 | TestEnum::get('1'); |
||
| 125 | } |
||
| 126 | |||
| 127 | |||
| 128 | /** |
||
| 129 | * @test |
||
| 130 | */ |
||
| 131 | public function isShouldAllowToCallMethodsBasedOnConstantNames(): void |
||
| 132 | { |
||
| 133 | $enum = TestEnum::nameWithUnderscore(); |
||
| 134 | |||
| 135 | self::assertInstanceOf(TestEnum::class, $enum); |
||
| 136 | self::assertSame(TestEnum::NAME_WITH_UNDERSCORE, $enum->getValue()); |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @expectedException \BadMethodCallException |
||
| 141 | * @expectedExceptionMessage Werkspot\Instapro\Common\Test\Unit\Enum\TestEnum::isDoesNotExist() does not exist |
||
| 142 | */ |
||
| 143 | public function isShouldThrowAnExceptionWhenWhenCallingAnInvalidMethod(): void |
||
| 144 | { |
||
| 145 | TestEnum::isDoesNotExist(); |
||
| 146 | } |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @test |
||
| 150 | */ |
||
| 151 | public function getValidOptions(): void |
||
| 152 | { |
||
| 153 | self::assertSame( |
||
| 154 | [ |
||
| 155 | TestEnum::A, |
||
| 156 | TestEnum::B, |
||
| 157 | TestEnum::A1, |
||
| 158 | TestEnum::A3, |
||
| 159 | TestEnum::ANULL, |
||
| 160 | TestEnum::NAME_WITH_UNDERSCORE, |
||
| 161 | ], |
||
| 162 | TestEnum::getValidOptions() |
||
| 163 | ); |
||
| 164 | } |
||
| 165 | } |
||
| 166 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: