mirror of
https://github.com/danog/psalm-plugin-laravel.git
synced 2024-12-03 10:07:49 +01:00
935357a7c8
test: add test case for abort()
52 lines
1.1 KiB
Gherkin
52 lines
1.1 KiB
Gherkin
Feature: abort_if()
|
|
The global abort_if helper is supported
|
|
|
|
Background:
|
|
Given I have the following config
|
|
"""
|
|
<?xml version="1.0"?>
|
|
<psalm totallyTyped="true">
|
|
<projectFiles>
|
|
<directory name="."/>
|
|
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
|
|
</projectFiles>
|
|
<plugins>
|
|
<pluginClass class="Psalm\LaravelPlugin\Plugin"/>
|
|
</plugins>
|
|
</psalm>
|
|
"""
|
|
And I have the following code preamble
|
|
"""
|
|
<?php declare(strict_types=1);
|
|
"""
|
|
|
|
Scenario: abort asserts not null
|
|
Given I have the following code
|
|
"""
|
|
/**
|
|
* @param string|null $nullable
|
|
*/
|
|
function test($nullable): string {
|
|
if (!$nullable) {
|
|
abort(422);
|
|
}
|
|
|
|
return $nullable;
|
|
}
|
|
"""
|
|
|
|
Scenario: abort_if asserts not null
|
|
Given I have the following code
|
|
"""
|
|
/**
|
|
* @param string|null $nullable
|
|
*/
|
|
function abortIfNullable($nullable): string {
|
|
abort_if(is_null($nullable), 422);
|
|
|
|
return $nullable;
|
|
}
|
|
"""
|
|
When I run Psalm
|
|
Then I see no errors
|