Skip to content

Commit

Permalink
100% Psalm type coverage and 99% Infection MSI
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderer committed Feb 3, 2024
1 parent 2043646 commit f34ae55
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
26 changes: 3 additions & 23 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -11,31 +13,9 @@
<directory name="src" />
<directory name="tests/Psalm" />
<ignoreFiles>
<file name="src/Doctrine/PlatenumDoctrineType.php" />
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<UnusedClosureParam errorLevel="error">
<errorLevel type="suppress">
<file name="src/Doctrine/PlatenumDoctrineType.php" />
</errorLevel>
</UnusedClosureParam>
<UnusedPsalmSuppress errorLevel="error">
<errorLevel type="suppress">
<file name="src/Enum/AttributeEnumTrait.php" />
</errorLevel>
</UnusedPsalmSuppress>
<DeprecatedMethod errorLevel="error">
<errorLevel type="suppress">
<file name="src/Doctrine/PlatenumDoctrineType.php" />
</errorLevel>
</DeprecatedMethod>
<DocblockTypeContradiction errorLevel="error">
<errorLevel type="suppress">
<file name="src/Enum/EnumTrait.php" /> <!-- PHP 7.2 only? -->
</errorLevel>
</DocblockTypeContradiction>
</issueHandlers>

</psalm>
13 changes: 8 additions & 5 deletions src/Doctrine/PlatenumDoctrineType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
Expand Down Expand Up @@ -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')

Check warning on line 50 in src/Doctrine/PlatenumDoctrineType.php

View workflow job for this annotation

GitHub Actions / test (8.0, ubuntu-latest, false)

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return (string) $value; }; $sql = function (array $declaration, AbstractPlatform $platform) : string { - return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getStringTypeDeclarationSQL([]) : $platform->getVarcharTypeDeclarationSQL([]); + return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getVarcharTypeDeclarationSQL([]) : $platform->getStringTypeDeclarationSQL([]); }; self::registerCallback($alias, $class, $toString, $sql); }

Check warning on line 50 in src/Doctrine/PlatenumDoctrineType.php

View workflow job for this annotation

GitHub Actions / test (8.1, ubuntu-latest, false)

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return (string) $value; }; $sql = function (array $declaration, AbstractPlatform $platform) : string { - return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getStringTypeDeclarationSQL([]) : $platform->getVarcharTypeDeclarationSQL([]); + return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getVarcharTypeDeclarationSQL([]) : $platform->getStringTypeDeclarationSQL([]); }; self::registerCallback($alias, $class, $toString, $sql); }

Check warning on line 50 in src/Doctrine/PlatenumDoctrineType.php

View workflow job for this annotation

GitHub Actions / test (8.2, ubuntu-latest, false)

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return (string) $value; }; $sql = function (array $declaration, AbstractPlatform $platform) : string { - return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getStringTypeDeclarationSQL([]) : $platform->getVarcharTypeDeclarationSQL([]); + return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getVarcharTypeDeclarationSQL([]) : $platform->getStringTypeDeclarationSQL([]); }; self::registerCallback($alias, $class, $toString, $sql); }

Check warning on line 50 in src/Doctrine/PlatenumDoctrineType.php

View workflow job for this annotation

GitHub Actions / test (8.3, ubuntu-latest, false)

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return (string) $value; }; $sql = function (array $declaration, AbstractPlatform $platform) : string { - return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getStringTypeDeclarationSQL([]) : $platform->getVarcharTypeDeclarationSQL([]); + return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getVarcharTypeDeclarationSQL([]) : $platform->getStringTypeDeclarationSQL([]); }; self::registerCallback($alias, $class, $toString, $sql); }

Check warning on line 50 in src/Doctrine/PlatenumDoctrineType.php

View workflow job for this annotation

GitHub Actions / test (nightly, ubuntu-latest, true)

Escaped Mutant for Mutator "Ternary": --- Original +++ New @@ @@ return (string) $value; }; $sql = function (array $declaration, AbstractPlatform $platform) : string { - return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getStringTypeDeclarationSQL([]) : $platform->getVarcharTypeDeclarationSQL([]); + return method_exists($platform, 'getStringTypeDeclarationSQL') ? $platform->getVarcharTypeDeclarationSQL([]) : $platform->getStringTypeDeclarationSQL([]); }; self::registerCallback($alias, $class, $toString, $sql); }
? $platform->getStringTypeDeclarationSQL([])
: $platform->getVarcharTypeDeclarationSQL([]);
};

self::registerCallback($alias, $class, $toString, $sql);
Expand All @@ -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<mixed>,AbstractPlatform):string $sql
*/
private static function registerCallback(string $alias, string $class, callable $callback, callable $sql): void
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/DoctrineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
9 changes: 8 additions & 1 deletion tests/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions tests/Fake/DoctrineExtendsBaseEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
declare(strict_types=1);
namespace Thunder\Platenum\Tests\Fake;

abstract class DoctrineExtendsBaseEnum extends DoctrineExtendsCoreEnum
{
}
10 changes: 10 additions & 0 deletions tests/Fake/DoctrineExtendsCoreEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Thunder\Platenum\Tests\Fake;

use Thunder\Platenum\Enum\ConstantsEnumTrait;

abstract class DoctrineExtendsCoreEnum
{
use ConstantsEnumTrait;
}
13 changes: 13 additions & 0 deletions tests/Fake/DoctrineExtendsEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
declare(strict_types=1);
namespace Thunder\Platenum\Tests\Fake;

/**
* @method static static ONE()
* @method static static TWO()
*/
final class DoctrineExtendsEnum extends DoctrineExtendsBaseEnum
{
private const ONE = 'one';
private const TWO = 'two';
}

0 comments on commit f34ae55

Please sign in to comment.