diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 824ff8c..eb09295 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -35,7 +35,7 @@ jobs:
continue-on-error: '${{ matrix.failure }}'
- name: 'Psalm'
run: 'php vendor/bin/psalm --no-cache --shepherd'
- continue-on-error: '${{ matrix.failure }}'
+ if: always()
- name: 'Infection'
run: 'php vendor/bin/infection -j2 --min-msi=95'
- continue-on-error: '${{ matrix.failure }}'
+ if: always()
diff --git a/psalm.xml b/psalm.xml
index 8e29c4f..8cbfd37 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -3,6 +3,8 @@
errorLevel="1"
resolveFromConfigFile="true"
findUnusedPsalmSuppress="false"
+ findUnusedBaselineEntry="false"
+ findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
@@ -11,31 +13,9 @@
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/Doctrine/PlatenumDoctrineType.php b/src/Doctrine/PlatenumDoctrineType.php
index 8c194fc..83ba7ed 100644
--- a/src/Doctrine/PlatenumDoctrineType.php
+++ b/src/Doctrine/PlatenumDoctrineType.php
@@ -4,6 +4,7 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
+use Thunder\Platenum\Enum\AbstractConstantsEnum;
use Thunder\Platenum\Enum\EnumTrait;
/** @psalm-suppress PropertyNotSetInConstructor, MissingConstructor */
@@ -13,7 +14,7 @@ final class PlatenumDoctrineType extends Type
private $platenumClass;
/** @var string */
private $platenumAlias;
- /** @var callable */
+ /** @var callable(mixed):mixed */
private $platenumCallback;
/** @psalm-var callable(array,AbstractPlatform):string */
private $platenumSql;
@@ -46,7 +47,9 @@ public static function registerString(string $alias, string $class): void
return (string)$value;
};
$sql = function(array $declaration, AbstractPlatform $platform): string {
- return $platform->getVarcharTypeDeclarationSQL([]);
+ return method_exists($platform, 'getStringTypeDeclarationSQL')
+ ? $platform->getStringTypeDeclarationSQL([])
+ : $platform->getVarcharTypeDeclarationSQL([]);
};
self::registerCallback($alias, $class, $toString, $sql);
@@ -55,7 +58,7 @@ public static function registerString(string $alias, string $class): void
/**
* @param string $alias
* @psalm-param class-string $class
- * @param callable $callback
+ * @param callable(int|string):mixed $callback
* @psalm-param callable(array,AbstractPlatform):string $sql
*/
private static function registerCallback(string $alias, string $class, callable $callback, callable $sql): void
@@ -120,8 +123,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
throw new \LogicException(sprintf($message, self::class, gettype($value)));
}
- /** @psalm-suppress MixedMethodCall */
- return ($this->platenumCallback)($value->getValue());
+ /** @var AbstractConstantsEnum $value */
+ return call_user_func($this->platenumCallback, $value->getValue());
}
public function convertToPHPValue($value, AbstractPlatform $platform)
diff --git a/tests/DoctrineTest.php b/tests/DoctrineTest.php
index b8ab583..c2c3ebb 100644
--- a/tests/DoctrineTest.php
+++ b/tests/DoctrineTest.php
@@ -10,6 +10,7 @@
use Doctrine\Persistence\Mapping\Driver\StaticPHPDriver;
use Thunder\Platenum\Doctrine\PlatenumDoctrineType;
use Thunder\Platenum\Tests\Fake\DoctrineEntity;
+use Thunder\Platenum\Tests\Fake\DoctrineExtendsEnum;
use Thunder\Platenum\Tests\Fake\DoctrineIntEnum;
use Thunder\Platenum\Tests\Fake\DoctrineStringEnum;
use Thunder\Platenum\Tests\Fake\NoTraitEnum;
@@ -101,4 +102,10 @@ public function testNoTrait(): void
$this->expectExceptionMessage('PlatenumDoctrineType allows only Platenum enumerations, `'.NoTraitEnum::class.'` given.');
PlatenumDoctrineType::registerString('noTraitEnum', NoTraitEnum::class);
}
+
+ public function testInheritance(): void
+ {
+ PlatenumDoctrineType::registerString('doctrineExtendsEnum', DoctrineExtendsEnum::class);
+ $this->assertTrue(true);
+ }
}
diff --git a/tests/EnumTest.php b/tests/EnumTest.php
index 81c6ce9..2029b0a 100644
--- a/tests/EnumTest.php
+++ b/tests/EnumTest.php
@@ -65,7 +65,14 @@ public function testGetInstances(): void
$first = $enum::fromMember('FIRST');
$otherFirst = $enum::fromEnum($first);
- $this->assertSame([$enum::FIRST(), $enum::SECOND()], $enum::getInstances());
+ $this->assertSame([$first, $enum::SECOND()], $enum::getInstances());
+ }
+
+ public function testGetInstancesCold(): void
+ {
+ $enum = $this->makeRawEnum(['FIRST' => 1, 'SECOND' => 2]);
+
+ $this->assertCount(2, $enum::getInstances());
}
public function testExceptionNonScalarValue(): void
diff --git a/tests/Fake/DoctrineExtendsBaseEnum.php b/tests/Fake/DoctrineExtendsBaseEnum.php
new file mode 100644
index 0000000..1da0c88
--- /dev/null
+++ b/tests/Fake/DoctrineExtendsBaseEnum.php
@@ -0,0 +1,7 @@
+