fp4php / psalm-toolkit
Testing tool for psalm plugins
Installs: 2 722
Dependents: 2
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.0
- vimeo/psalm: ^4.26
Requires (Dev)
- fp4php/functional: ^5.0
README
Helpers for plugin authoring and static testing tool.
Installation
Package fp4php/functional
must be installed manually.
$ composer require --dev fp4php/functional fp4php/psalm-toolkit
$ vendor/bin/psalm-plugin enable fp4php/psalm-toolkit
Usage
At the moment you can use two methods for static asserts:
seePsalmIssue
: Checks that a code block from thehaveCode
have specific issue.seeReturnType
: Verifies a return type from thehaveCode
block.
Usage example below:
<?php namespace Fp\Decode\Test\Static; use Fp\PsalmToolkit\StaticTest\PsalmTest; use Fp\PsalmToolkit\StaticTest\StaticTestCase; use Fp\PsalmToolkit\StaticType\StaticTypes as t; final class ExampleTest extends PsalmTest { public function __invoke(): void { StaticTestCase::describe('See InvalidScalarArgument issue') ->haveCode(function() { $plus = fn(int $a, int $b): int => $a + $b; $plus(10, 10.00); }) ->seePsalmIssue( type: 'InvalidScalarArgument', message: 'Argument 2 expects int, float(10) provided', ); StaticTestCase::describe('See return type (invariant type compare)') ->haveCode(function() { return [ 'twenty' => 10 + 10, 'message' => 'Hello world!' ]; }) ->seeReturnType( is: t::shape([ 'twenty' => t::literal(20), 'message' => t::literal('Hello world!'), ]), ); StaticTestCase::describe('See return type (covariant type compare)') ->haveCode(function() { return [ 'twenty' => 10 + 10, 'message' => 'Hello world!' ]; }) ->seeReturnType( is: t::shape([ 'twenty' => t::int(), 'message' => t::string(), ]), invariant: false, ); } }