Skip to content

Commit 14a6864

Browse files
committed
Separate enum tests
1 parent ea58997 commit 14a6864

File tree

4 files changed

+78
-51
lines changed

4 files changed

+78
-51
lines changed

tests/PHPStan/Reflection/Deprecation/DeprecationProviderTest.php

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class DeprecationProviderTest extends PHPStanTestCase
2222

2323
public function testCustomDeprecations(): void
2424
{
25-
if (PHP_VERSION_ID < 80100) {
26-
self::markTestSkipped('PHP 8.1+ is required to test enums.');
25+
if (PHP_VERSION_ID < 80000) {
26+
self::markTestSkipped('PHP 8.0+ is required as CustomDeprecationProvider uses unions.');
2727
}
2828

2929
require __DIR__ . '/data/deprecations.php';
@@ -59,24 +59,6 @@ public function testCustomDeprecations(): void
5959
$scopeForDoubleDeprecatedClassOnlyNativeMessage = $scopeFactory->create(ScopeContext::create('dummy.php')->enterClass($doubleDeprecatedClassOnlyPhpDocMessage));
6060
$scopeForDoubleDeprecatedClassOnlyCustomMessage = $scopeFactory->create(ScopeContext::create('dummy.php')->enterClass($doubleDeprecatedClassOnlyAttributeMessage));
6161

62-
// enum cases
63-
$myEnum = $reflectionProvider->getClass(MyDeprecatedEnum::class);
64-
65-
self::assertTrue($myEnum->isDeprecated());
66-
self::assertNull($myEnum->getDeprecatedDescription());
67-
68-
self::assertTrue($myEnum->getEnumCase('CustomDeprecated')->isDeprecated()->yes());
69-
self::assertSame('custom', $myEnum->getEnumCase('CustomDeprecated')->getDeprecatedDescription());
70-
71-
self::assertTrue($myEnum->getEnumCase('NativeDeprecated')->isDeprecated()->yes());
72-
self::assertSame('native', $myEnum->getEnumCase('NativeDeprecated')->getDeprecatedDescription());
73-
74-
self::assertTrue($myEnum->getEnumCase('PhpDocDeprecated')->isDeprecated()->yes());
75-
self::assertNull($myEnum->getEnumCase('PhpDocDeprecated')->getDeprecatedDescription()); // this should not be null
76-
77-
self::assertFalse($myEnum->getEnumCase('NotDeprecated')->isDeprecated()->yes());
78-
self::assertNull($myEnum->getEnumCase('NotDeprecated')->getDeprecatedDescription());
79-
8062
// class
8163
self::assertFalse($notDeprecatedClass->isDeprecated());
8264
self::assertNull($notDeprecatedClass->getDeprecatedDescription());
@@ -203,6 +185,34 @@ public function testCustomDeprecations(): void
203185
self::assertSame('attribute', $doubleDeprecatedFunctionOnlyAttributeMessage->getDeprecatedDescription());
204186
}
205187

188+
public function testCustomDeprecationsOfEnumCases(): void
189+
{
190+
if (PHP_VERSION_ID < 80100) {
191+
self::markTestSkipped('PHP 8.1+ is required to test enums.');
192+
}
193+
194+
require __DIR__ . '/data/deprecations-enums.php';
195+
196+
$reflectionProvider = self::createReflectionProvider();
197+
198+
$myEnum = $reflectionProvider->getClass(MyDeprecatedEnum::class);
199+
200+
self::assertTrue($myEnum->isDeprecated());
201+
self::assertNull($myEnum->getDeprecatedDescription());
202+
203+
self::assertTrue($myEnum->getEnumCase('CustomDeprecated')->isDeprecated()->yes());
204+
self::assertSame('custom', $myEnum->getEnumCase('CustomDeprecated')->getDeprecatedDescription());
205+
206+
self::assertTrue($myEnum->getEnumCase('NativeDeprecated')->isDeprecated()->yes());
207+
self::assertSame('native', $myEnum->getEnumCase('NativeDeprecated')->getDeprecatedDescription());
208+
209+
self::assertTrue($myEnum->getEnumCase('PhpDocDeprecated')->isDeprecated()->yes());
210+
self::assertNull($myEnum->getEnumCase('PhpDocDeprecated')->getDeprecatedDescription()); // this should not be null
211+
212+
self::assertFalse($myEnum->getEnumCase('NotDeprecated')->isDeprecated()->yes());
213+
self::assertNull($myEnum->getEnumCase('NotDeprecated')->getDeprecatedDescription());
214+
}
215+
206216
public static function getAdditionalConfigFiles(): array
207217
{
208218
return [
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php // lint >= 8.1
2+
3+
namespace CustomDeprecations;
4+
5+
#[\Attribute(\Attribute::TARGET_ALL)]
6+
class CustomDeprecated {
7+
8+
public ?string $description;
9+
10+
public function __construct(
11+
?string $description = null
12+
) {
13+
$this->description = $description;
14+
}
15+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php // lint >= 8.1
2+
3+
namespace CustomDeprecations;
4+
5+
#[\Attribute(\Attribute::TARGET_ALL)]
6+
class CustomDeprecated {
7+
8+
public ?string $description;
9+
10+
public function __construct(
11+
?string $description = null
12+
) {
13+
$this->description = $description;
14+
}
15+
}
16+
17+
#[CustomDeprecated]
18+
enum MyDeprecatedEnum: string
19+
{
20+
#[CustomDeprecated('custom')]
21+
case CustomDeprecated = '1';
22+
23+
/**
24+
* @deprecated phpdoc
25+
*/
26+
case PhpDocDeprecated = '2';
27+
28+
#[\Deprecated('native')]
29+
case NativeDeprecated = '3';
30+
31+
case NotDeprecated = '4';
32+
33+
}

tests/PHPStan/Reflection/Deprecation/data/deprecations.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
namespace CustomDeprecations;
44

5-
#[\Attribute(\Attribute::TARGET_ALL)]
6-
class CustomDeprecated {
7-
8-
public ?string $description;
9-
10-
public function __construct(
11-
?string $description = null
12-
) {
13-
$this->description = $description;
14-
}
15-
}
16-
175
class NotDeprecatedClass
186
{
197
const FOO = 'foo';
@@ -161,22 +149,3 @@ function doubleDeprecatedFunctionOnlyAttributeMessage() {}
161149
/** @deprecated phpdoc */
162150
#[CustomDeprecated()]
163151
function doubleDeprecatedFunctionOnlyPhpDocMessage() {}
164-
165-
166-
#[CustomDeprecated]
167-
enum MyDeprecatedEnum: string
168-
{
169-
#[CustomDeprecated('custom')]
170-
case CustomDeprecated = '1';
171-
172-
/**
173-
* @deprecated phpdoc
174-
*/
175-
case PhpDocDeprecated = '2';
176-
177-
#[\Deprecated('native')]
178-
case NativeDeprecated = '3';
179-
180-
case NotDeprecated = '4';
181-
182-
}

0 commit comments

Comments
 (0)