Skip to content

Commit fba94bf

Browse files
committed
Fixed tests
1 parent 81c2abd commit fba94bf

7 files changed

Lines changed: 65 additions & 15 deletions

File tree

.github/workflows/test.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,32 @@ jobs:
1717
RUN_PHPSTAN: 'false'
1818
RUN_PSALM: 'false'
1919
- PHP_VERSION: '7.2'
20-
RUN_PHPSTAN: 'false'
20+
RUN_PHPSTAN: 'true'
2121
RUN_PSALM: 'false'
2222
- PHP_VERSION: '7.3'
2323
RUN_PHPSTAN: 'false'
2424
RUN_PSALM: 'false'
2525
- PHP_VERSION: '7.4'
26-
RUN_PHPSTAN: 'true'
27-
RUN_PSALM: 'true'
26+
RUN_PHPSTAN: 'false'
27+
RUN_PSALM: 'false'
2828
- PHP_VERSION: '8.0'
2929
RUN_PHPSTAN: 'true'
3030
RUN_PSALM: 'true'
3131
- PHP_VERSION: '8.1'
3232
RUN_PHPSTAN: 'false'
3333
RUN_PSALM: 'false'
34+
- PHP_VERSION: '8.2'
35+
RUN_PHPSTAN: 'false'
36+
RUN_PSALM: 'false'
37+
- PHP_VERSION: '8.3'
38+
RUN_PHPSTAN: 'false'
39+
RUN_PSALM: 'false'
40+
- PHP_VERSION: '8.4'
41+
RUN_PHPSTAN: 'false'
42+
RUN_PSALM: 'false'
43+
- PHP_VERSION: '8.5'
44+
RUN_PHPSTAN: 'true'
45+
RUN_PSALM: 'false'
3446

3547
steps:
3648
- uses: actions/checkout@v6

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"composer-runtime-api": "^2.0"
2222
},
2323
"require-dev": {
24-
"phpstan/phpstan": "^1.3.0",
25-
"phpunit/phpunit": "^7.5.20 | ^8.5.52 | ^9.6.33",
24+
"phpstan/phpstan": "^1.4.0",
25+
"phpunit/phpunit": "^7.5.20 | ^8.5.52 | ^9.6.34",
2626
"vimeo/psalm": "^4.17.0"
2727
},
2828
"autoload": {

examples/doctrine/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"license": "BSD-3-Clause",
1717
"require": {
1818
"php": "^7.1 | ^8.0",
19+
"ext-pdo_sqlite": "*",
1920
"marc-mabe/enum-cl": "@dev",
2021
"doctrine/orm": "2.9.6"
2122
},

src/functions.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ function get_debug_type($value): string
5151
return 'class@anonymous';
5252
default:
5353
/** @var resource $value */
54-
/** @var string|null $type */
5554
$type = @get_resource_type($value);
56-
if (null === $type) {
57-
return 'unknown';
58-
}
5955

6056
if ('Unknown' === $type) {
6157
$type = 'closed';

src/psr-4/EmulatedBackedEnumTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ trait EmulatedBackedEnumTrait
5757
/** @param string|int $value */
5858
final private function __construct(string $name, $value)
5959
{
60+
/** @phpstan-ignore-next-line */
6061
$this->name = $name;
6162

6263
/** @phpstan-ignore-next-line */

tests/BasicIntEnumTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ public function testFromSuccess(): void
3838

3939
public function testFromInvalidValue(): void
4040
{
41+
if (PHP_VERSION_ID < 80200) {
42+
$enumClass = '"' . BasicIntEnum::class . '"';
43+
} else {
44+
$enumClass = BasicIntEnum::class;
45+
}
46+
47+
$this->expectExceptionMessage("10 is not a valid backing value for enum {$enumClass}");
4148
$this->expectException('ValueError');
42-
$this->expectExceptionMessage('10 is not a valid backing value for enum "BasicIntEnum"');
4349
BasicIntEnum::from(10);
4450
}
4551

@@ -74,13 +80,20 @@ public function testFromUnexpectedBoolTypeError(): void
7480
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
7581
$class = EmulatedIntEnum::class;
7682
$type = 'string|int';
83+
$given = 'bool';
7784
} else {
7885
$class = BasicIntEnum::class;
7986
$type = 'int';
87+
88+
if (PHP_VERSION_ID >= 80300) {
89+
$given = 'true';
90+
} else {
91+
$given = 'bool';
92+
}
8093
}
8194

8295
$this->expectException('TypeError');
83-
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, bool given");
96+
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, {$given} given");
8497

8598
/** @phpstan-ignore-next-line */
8699
BasicIntEnum::from(true);
@@ -169,13 +182,20 @@ public function testTryFromUnexpectedBoolTypeError(): void
169182
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
170183
$class = EmulatedIntEnum::class;
171184
$type = 'string|int';
185+
$given = 'bool';
172186
} else {
173187
$class = BasicIntEnum::class;
174188
$type = 'int';
189+
190+
if (PHP_VERSION_ID >= 80300) {
191+
$given = 'true';
192+
} else {
193+
$given = 'bool';
194+
}
175195
}
176196

177197
$this->expectException('TypeError');
178-
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, bool given");
198+
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, {$given} given");
179199

180200
/** @phpstan-ignore-next-line */
181201
BasicIntEnum::tryFrom(true);

tests/BasicStringEnumTest.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ public function testFromSuccess(): void
3838

3939
public function testFromInvalidValue(): void
4040
{
41+
if (PHP_VERSION_ID < 80200) {
42+
$enumClass = '"' . BasicStringEnum::class . '"';
43+
} else {
44+
$enumClass = BasicStringEnum::class;
45+
}
46+
47+
$this->expectExceptionMessage("\"10\" is not a valid backing value for enum {$enumClass}");
4148
$this->expectException('ValueError');
42-
$this->expectExceptionMessage('"10" is not a valid backing value for enum "BasicStringEnum"');
4349
BasicStringEnum::from('10');
4450
}
4551

@@ -74,13 +80,20 @@ public function testFromUnexpectedBoolTypeError(): void
7480
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
7581
$class = EmulatedStringEnum::class;
7682
$type = 'string|int';
83+
$given = 'bool';
7784
} else {
7885
$class = BasicStringEnum::class;
7986
$type = 'string';
87+
88+
if (PHP_VERSION_ID >= 80300) {
89+
$given = 'true';
90+
} else {
91+
$given = 'bool';
92+
}
8093
}
8194

8295
$this->expectException('TypeError');
83-
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, bool given");
96+
$this->expectExceptionMessage("{$class}::from(): Argument #1 (\$value) must be of type {$type}, {$given} given");
8497

8598
/** @phpstan-ignore-next-line */
8699
BasicStringEnum::from(true);
@@ -169,13 +182,20 @@ public function testTryFromUnexpectedBoolTypeError(): void
169182
if (PHP_VERSION_ID >= 80000 && PHP_VERSION_ID < 80100) {
170183
$class = EmulatedStringEnum::class;
171184
$type = 'string|int';
185+
$given = 'bool';
172186
} else {
173187
$class = BasicStringEnum::class;
174188
$type = 'string';
189+
190+
if (PHP_VERSION_ID >= 80300) {
191+
$given = 'true';
192+
} else {
193+
$given = 'bool';
194+
}
175195
}
176196

177197
$this->expectException('TypeError');
178-
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, bool given");
198+
$this->expectExceptionMessage("{$class}::tryFrom(): Argument #1 (\$value) must be of type {$type}, {$given} given");
179199

180200
/** @phpstan-ignore-next-line */
181201
BasicStringEnum::tryFrom(true);

0 commit comments

Comments
 (0)