https://github.com/ghostwriter/psalm-sandbox
Provides a framework for testing Psalm plugins with PHPUnit
https://github.com/ghostwriter/psalm-sandbox
ghostwriter psalm-plugin psalm-plugin-tester
Last synced: 28 days ago
JSON representation
Provides a framework for testing Psalm plugins with PHPUnit
- Host: GitHub
- URL: https://github.com/ghostwriter/psalm-sandbox
- Owner: ghostwriter
- License: bsd-3-clause
- Created: 2023-07-01T19:37:06.000Z (almost 2 years ago)
- Default Branch: 0.2.x
- Last Pushed: 2025-02-11T00:33:21.000Z (3 months ago)
- Last Synced: 2025-02-19T19:04:35.112Z (3 months ago)
- Topics: ghostwriter, psalm-plugin, psalm-plugin-tester
- Language: PHP
- Homepage: https://github.com/ghostwriter/psalm-plugin
- Size: 503 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Psalm Sandbox
[](https://github.com/sponsors/ghostwriter)
[](https://github.com/ghostwriter/psalm-sandbox/actions/workflows/automation.yml)
[](https://www.php.net/supported-versions)
[](https://packagist.org/packages/ghostwriter/psalm-sandbox)work in progress
> [!WARNING]
>
> This project is not finished yet, work in progress.## Installation
You can install the package via composer:
``` bash
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
*/
public const PLUGINS = [ExamplePlugin::class];/**
* @var array>
*/
public const ISSUES = [MissingReturnType::class];
}
```You can then run your tests using PHPUnit.
``` bash
vendor/bin/phpunit
```## Plugin Development
### Example Directory Structure
Your plugin should have the following directory structure:
``` text
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
--FIX--
```
### 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