Skip to content

Commit

Permalink
Improved compatibility fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
vudaltsov committed Feb 28, 2024
1 parent 2a3688a commit dd96c2c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 6 deletions.
2 changes: 1 addition & 1 deletion psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@

<stubs>
<file name="tests/unit/Fixtures/classes.php" preloadClasses="true"/>
<file name="tests/unit/Fixtures/readonly_classes.php" preloadClasses="true"/>
<file name="tests/unit/Fixtures/classes_php82.php" preloadClasses="true"/>
<file name="stubs/PhpParser/Node/Expr/Variable.phpstub"/>
<file name="stubs/PhpParser/Node/Identifier.phpstub"/>
<file name="stubs/PhpParser/Node/IntersectionType.phpstub"/>
Expand Down
28 changes: 26 additions & 2 deletions tests/unit/Fixtures/classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@ class JustClass {}

enum JustEnum {}

enum IntEnum: int {}
enum EmptyIntEnum: int {}

enum StringEnum: string {}
enum IntEnum: int
{
case ONE = 1;
case TWO = 2;
}

enum EmptyStringEnum: string {}

enum StringEnum: string
{
case A = 'a';
case B = 'b';
}

interface JustInterface {}

Expand Down Expand Up @@ -467,3 +479,15 @@ public function publicMethod(): void {}
private function t2PublicAsPrivate(): void {}
}
}

namespace Constants
{
class ClassWithConstants
{
const CONSTANT_WITHOUT_VISIBILITY = null;
public const PUBLIC_CONSTANT = 1;
protected const PROTECTED_CONSTANT = 'protected';
protected const PRIVATE_CONSTANT = 0.34;
final protected const FINAL_CONSTANT = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace ReadonlyClasses;
namespace Classes\PHP82;

readonly class ReadonlyClass {}

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/FixturesProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ public static function classes(): array
...self::loadFromFile(__DIR__ . '/Fixtures/classes.php'),
];

if (PHP_VERSION >= 80200) {
if (\PHP_VERSION_ID >= 80200) {
self::$classes = [
...self::$classes,
...self::loadFromFile(__DIR__ . '/Fixtures/readonly_classes.php'),
...self::loadFromFile(__DIR__ . '/Fixtures/classes_php82.php'),
];
}

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/ReflectorCompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,10 @@ private function assertSameNames(array $nativeReflections, array $typhoonReflect

private function canCreateMockObject(\ReflectionClass $class): bool
{
if (method_exists($class, 'isReadonly') && $class->isReadonly()) {
return false;
}

if ($class->isTrait()) {
return false;
}
Expand Down

0 comments on commit dd96c2c

Please sign in to comment.