klimick/psalm-test

This package is abandoned and no longer maintained. The author suggests using the fp4php/psalm-toolkit package instead.

Testing tool for psalm plugins

Maintainers

👁 klimick

Package info

github.com/klimick/psalm-test

pkg:composer/klimick/psalm-test

Statistics

Installs: 176

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

v1.2.3 2022-01-12 16:02 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 43b04f4d12956c8bb2cdc7aa791315fe1a5ecee1

  • adrew <klimichkartorgnusov.woop@gmail.com>

This package is not auto-updated.

Last update: 2022-05-31 17:38:50 UTC


README

Static testing tool for psalm plugins.

Installation

$ composer require --dev klimick/psalm-test
$ vendor/bin/psalm-plugin enable klimick/psalm-test

Usage

At the moment you can use two methods for static asserts:

  • seePsalmIssue: Checks that a code block from the haveCode have specific issue.
  • seeReturnType: Verifies a return type from the haveCode block.

Usage example below:

<?php

namespace Klimick\Decode\Test\Static;

use Klimick\PsalmTest\PsalmTest;
use Klimick\PsalmTest\StaticTestCase;
use Klimick\PsalmTest\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,
 );
 }
}