These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php declare(strict_types = 1); |
||
2 | |||
3 | namespace SlevomatEET\Type; |
||
4 | |||
5 | class EnumTest extends \PHPUnit_Framework_TestCase |
||
6 | { |
||
7 | |||
8 | public function testEqualsInstances() |
||
9 | { |
||
10 | $review1 = new StatusEnum(StatusEnum::REVIEW); |
||
11 | $review2 = new StatusEnum(StatusEnum::REVIEW); |
||
12 | |||
13 | $this->assertEquals($review1, $review2); |
||
14 | } |
||
15 | |||
16 | public function testDifferentInstances() |
||
17 | { |
||
18 | $review = new StatusEnum(StatusEnum::REVIEW); |
||
19 | $draft = new StatusEnum(StatusEnum::DRAFT); |
||
20 | |||
21 | $this->assertNotEquals($review, $draft); |
||
22 | } |
||
23 | |||
24 | public function testGetValue() |
||
25 | { |
||
26 | $review = new StatusEnum(StatusEnum::REVIEW); |
||
27 | |||
28 | $this->assertSame(StatusEnum::REVIEW, $review->getValue()); |
||
29 | } |
||
30 | |||
31 | public function testEqualsValue() |
||
32 | { |
||
33 | $review = new StatusEnum(StatusEnum::REVIEW); |
||
34 | $draft = new StatusEnum(StatusEnum::DRAFT); |
||
35 | |||
36 | $this->assertTrue($review->equalsValue(StatusEnum::REVIEW)); |
||
37 | $this->assertFalse($draft->equalsValue(StatusEnum::REVIEW)); |
||
38 | } |
||
39 | |||
40 | public function testEquals() |
||
41 | { |
||
42 | $review1 = new StatusEnum(StatusEnum::REVIEW); |
||
43 | $review2 = new StatusEnum(StatusEnum::REVIEW); |
||
44 | $draft = new StatusEnum(StatusEnum::DRAFT); |
||
45 | |||
46 | $this->assertTrue($review1->equals($review2)); |
||
0 ignored issues
–
show
|
|||
47 | $this->assertFalse($review1->equals($draft)); |
||
0 ignored issues
–
show
$draft is of type object<SlevomatEET\Type\StatusEnum> , 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...
|
|||
48 | |||
49 | $admin = new RoleEnum(RoleEnum::ADMIN); |
||
50 | try { |
||
51 | $review1->equals($admin); |
||
0 ignored issues
–
show
$admin is of type object<SlevomatEET\Type\RoleEnum> , 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...
|
|||
52 | $this->fail(); |
||
53 | |||
54 | } catch (InvalidEnumTypeException $e) { |
||
55 | $this->assertSame($admin, $e->getEnum()); |
||
56 | $this->assertSame(get_class($review1), $e->getExpectedClass()); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | public function testInvalidEnumValue() |
||
61 | { |
||
62 | try { |
||
63 | new StatusEnum(10); |
||
64 | $this->fail(); |
||
65 | |||
66 | } catch (InvalidEnumValueException $e) { |
||
67 | $this->assertSame('Invalid enum value \'10\' (integer). Available values: 1, 2, 3', $e->getMessage()); |
||
68 | $this->assertSame(10, $e->getValue()); |
||
69 | $this->assertEquals([ |
||
70 | 'DRAFT' => StatusEnum::DRAFT, |
||
71 | 'REVIEW' => StatusEnum::REVIEW, |
||
72 | 'PUBLISHED' => StatusEnum::PUBLISHED, |
||
73 | ], $e->getAvailableValues()); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | public function testInvalidEnumValueType() |
||
78 | { |
||
79 | try { |
||
80 | new StatusEnum('10'); |
||
81 | $this->fail(); |
||
82 | |||
83 | } catch (InvalidEnumValueException $e) { |
||
84 | $this->assertSame('Invalid enum value \'10\' (string). Available values: 1, 2, 3', $e->getMessage()); |
||
85 | $this->assertSame('10', $e->getValue()); |
||
86 | } |
||
87 | } |
||
88 | |||
89 | } |
||
90 |
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: