phariscope / doctrineenumtype

快速创建并测试 Doctrine 枚举类型的工具

v0.0.4 2024-05-03 07:42 UTC

This package is auto-updated.

Last update: 2024-09-03 10:08:46 UTC


README

要使用 Doctrine 持久化 PHP 枚举字段,您必须为每个枚举创建一个 Doctrine 枚举类型类。

为了保持简单并减少测试量,请使用 EnumType。

安装

composer require phariscope/doctrineenumtype

使用方法

像平常一样创建枚举对象。例如

enum Example: string
{
    case EXAMPLE = 'EXAMPLE';
    case FAKE = 'FAKE';
    case REAL = 'REAL';
}

创建您的 Doctrine 枚举类型测试。例如

class ExampleTypeTest extends TestCase
{
    public function testGetName(): void
    {
        $this->assertEquals('enum_example', (new ExampleType())->getName());
    }

您的生产代码源代码将非常短,看起来像这样

use Phariscope\DoctrineEnumType\EnumType;

class ExampleType extends EnumType
{
    protected string $name = "enum_example";
    protected string $className = EnumExample::class;
}

现在您可以使用这个新的 'ExampleType' 与 Doctrine ORM 一起使用。

<field name="myExample" type="enum_example" column="my_example"/>

当然,别忘了在您的应用程序中某处声明这个新类型给 Doctrine (Type::addType("enum_example", ExampleType::class))。

为 phariscope/DoctrineEnumType 做贡献

要求

  • docker
  • git

安装

git clone git@github.com:phariscope/DoctrineEnumType.git
cd DoctrineEnumType
./install

安装将加载 PHP Docker 镜像并执行 composer install,因此所有包含在 'bin' 文件夹中的命令都将易于访问。

示例

bin/php -v

单元测试

bin/phpunit

遵循测试驱动开发 (TDD) 原则(感谢 Kent Beck 和其他人),遵循良好实践(感谢 Uncle Bob 和其他人)。

质量

  • phpcs PSR12
  • phpstan 级别 9
  • 覆盖率 100%
  • infection MSI >99%

使用以下命令快速检查

./codecheck

使用以下命令检查覆盖率

bin/phpunit --coverage-html var

并使用浏览器查看 'var/index.html'

使用以下命令检查 infection

bin/infection

并使用浏览器查看 'var/infection.html'