mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-12-12 17:17:33 +01:00
76 lines
1.9 KiB
Gherkin
76 lines
1.9 KiB
Gherkin
Feature: Request getContent
|
|
Symfony Request has getContent method on which return type changes based on argument
|
|
|
|
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\SymfonyPsalmPlugin\Plugin"/>
|
|
</plugins>
|
|
</psalm>
|
|
"""
|
|
|
|
Scenario: Asserting '$request->getContent()' without any argument returns string
|
|
Given I have the following code
|
|
"""
|
|
<?php
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class App
|
|
{
|
|
public function index(Request $request): void
|
|
{
|
|
json_decode($request->getContent());
|
|
}
|
|
}
|
|
"""
|
|
When I run Psalm
|
|
Then I see no errors
|
|
|
|
Scenario: Asserting '$request->getContent(false)' returns string
|
|
Given I have the following code
|
|
"""
|
|
<?php
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class App
|
|
{
|
|
public function index(Request $request): void
|
|
{
|
|
json_decode($request->getContent(false));
|
|
}
|
|
}
|
|
"""
|
|
When I run Psalm
|
|
Then I see no errors
|
|
|
|
Scenario: Asserting '$request->getContent(true)' returns resource
|
|
Given I have the following code
|
|
"""
|
|
<?php
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
class App
|
|
{
|
|
public function index(Request $request): void
|
|
{
|
|
json_decode($request->getContent(true));
|
|
}
|
|
}
|
|
"""
|
|
When I run Psalm
|
|
Then I see these errors
|
|
| Type | Message |
|
|
| InvalidArgument | Argument 1 of json_decode expects string, resource provided |
|
|
And I see no other errors
|