ghostwriter/psalm-plugin-tester 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ghostwriter/psalm-plugin-tester

最新稳定版本:0.2.1

Composer 安装命令:

composer require --dev ghostwriter/psalm-plugin-tester

包简介

Provides a framework for testing Psalm plugins

README 文档

README

GitHub Sponsors Automation Supported PHP Version Downloads

work in progress

Warning

This project is not finished yet, work in progress.

Installation

You can install the package via composer:

composer require ghostwriter/psalm-sandbox --dev

Usage

You can create a test for your plugin by extending the AbstractPsalmSandboxTestCase class.

eg. tests/Unit/ExamplePluginTest.php

<?php

declare(strict_types=1);

namespace Vendor\PackageTests\Unit;

use Ghostwriter\PsalmSandbox\AbstractPsalmSandboxTestCase;
use Psalm\Issue\CodeIssue;
use Psalm\Issue\MissingReturnType;
use Psalm\Plugin\PluginEntryPointInterface;
use Vendor\Package\ExamplePlugin;

final class ExamplePluginTest extends AbstractPsalmSandboxTestCase
{
    /**
     * @var class-string<PluginEntryPointInterface>
     */
    public const PLUGINS = [ExamplePlugin::class];

    /**
     * @var array<class-string<CodeIssue>>
     */
    public const ISSUES = [MissingReturnType::class];
}

You can then run your tests using PHPUnit.

vendor/bin/phpunit

Plugin Development

Example Directory Structure

Your plugin should have the following directory structure:

composer.json
ExamplePlugin.php
src/
│   {PsalmIssueType}/
│   │   {FixIssue}.php
│   │   {ReportIssue}.php
│   │   {SuppressIssue}.php
│   MissingReturnType/
│   │   FixMissingReturnType.php
│   │   ReportMissingReturnType.php
│   │   SuppressMissingReturnType.php
tests/
│   Fixture/
│   │   {PsalmIssueType}/
│   │   │   fix-{PsalmIssueType}.php.inc
│   │   │   report-{PsalmIssueType}.php.inc
│   │   │   suppress-{PsalmIssueType}.php.inc
│   │   MissingReturnType/
│   │   │   fix-0001.php.inc
│   │   │   fix-missing-returntype.php.inc
│   │   │   report-0001.php.inc
│   │   │   report-missing-returntype.php.inc
│   │   │   suppress-0001.php.inc
│   │   │   suppress-missing-returntype.php.inc
│   Unit/
│   │   ExamplePluginTest.php

Example Fix Test

When you run vendor/bin/psalm --alter, it will automatically fix the code for you.

To create a Fix test, you need to create a file in the tests/Fixture/{PsalmIssueType} directory.

The file name should be prefixed with fix- and any unique identifier, e.g. fix-0001.php.inc.

The file MUST use --FIX-- to separate the before and after code.

The file should be structured as follows:

<?php

declare(strict_types=1);

namespace Vendor\PackageTests\Fixture\MissingReturnType;

final class FixMissingReturnType
{
    public function fixMissingReturnType()
    {
    }
}
?>
--FIX--
<?php

declare(strict_types=1);

namespace Vendor\PackageTests\Fixture\MissingReturnType;

final class FixMissingReturnType
{
    public function fixMissingReturnType(): void
    {
    }
}
?>

Example Report Test

When you run vendor/bin/psalm, it will report the issue in your code.

To create a Report test, you need to create a file in the tests/Fixture/{PsalmIssueType} directory.

The file name should be prefixed with report- and any unique identifier, e.g. report-0001.php.inc.

The file should be structured as follows:

<?php

declare(strict_types=1);

namespace Vendor\PackageTests\Fixture\MissingReturnType;

final class ReportMissingReturnType
{
    public function reportMissingReturnType()
    {
    }
}

Example Suppress Test

You can suppress the issue in your code by adding the @psalm-suppress annotation, adding suppressions to your psalm.xml file, or using a plugin.

To create a Suppress test, you need to create a file in the tests/Fixture/{PsalmIssueType} directory.

The file name should be prefixed with suppress- and any unique identifier, e.g. suppress-0001.php.inc.

The file should be structured as follows:

<?php

declare(strict_types=1);

namespace Vendor\PackageTests\Fixture\MissingReturnType;

final class SuppressMissingReturnType
{
    /**
     * @psalm-suppress MissingReturnType
     */
    public function suppressMissingReturnType()
    {
    }
}

Testing

composer test

Changelog

Please see CHANGELOG.md for more information what has changed recently.

Security

If you discover any security related issues, please email nathanael.esayeas@protonmail.com instead of using the issue tracker.

Support

[Become a GitHub Sponsor]

Thank you

To acknowledge the efforts of those who create and maintain valuable projects for the community.

Thank you to Bruce Weirdan for the original psalm/codeception-psalm-module that served as the starting point for my work.

Thank you to Matt Brown, the creator of vimeo/psalm, a fantastic tool for static analysis in PHP.

Special thanks to @orklah for maintaining vimeo/psalm, ensuring its continuous improvement and functionality.

Credits

License

The BSD-3-Clause. Please see License File for more information.

ghostwriter/psalm-plugin-tester 适用场景与选型建议

ghostwriter/psalm-plugin-tester 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 204.07k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2023 年 07 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「ghostwriter」 「psalm-plugin-tester」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 ghostwriter/psalm-plugin-tester 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ghostwriter/psalm-plugin-tester 我们能提供哪些服务?
定制开发 / 二次开发

基于 ghostwriter/psalm-plugin-tester 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 204.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 17
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2023-07-01