mirror of
https://github.com/danog/psalm-plugin-symfony.git
synced 2024-11-26 20:04:58 +01:00
Added CacheInterface.stubphp from symfony contracts (#74)
This commit is contained in:
parent
898d580c13
commit
9fb76499f9
@ -18,6 +18,7 @@
|
||||
"require-dev": {
|
||||
"doctrine/orm": "^2.7",
|
||||
"phpunit/phpunit": "~7.5",
|
||||
"symfony/cache-contracts": "^1.0 || ^2.0",
|
||||
"symfony/console": "*",
|
||||
"symfony/messenger": "^4.2 || ^5.0",
|
||||
"symfony/security-guard": "^4.0 || ^5.0",
|
||||
|
16
src/Stubs/common/CacheInterface.stubphp
Normal file
16
src/Stubs/common/CacheInterface.stubphp
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Contracts\Cache;
|
||||
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
|
||||
interface CacheInterface
|
||||
{
|
||||
/**
|
||||
* @template T
|
||||
*
|
||||
* @psalm-param CallbackInterface|callable(CacheItemInterface, bool): T $callback
|
||||
* @psalm-return T
|
||||
*/
|
||||
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null);
|
||||
}
|
37
tests/acceptance/acceptance/CacheInterface.feature
Normal file
37
tests/acceptance/acceptance/CacheInterface.feature
Normal file
@ -0,0 +1,37 @@
|
||||
@symfony-common
|
||||
Feature: CacheInterface
|
||||
|
||||
Background:
|
||||
Given I have the following config
|
||||
"""
|
||||
<?xml version="1.0"?>
|
||||
<psalm errorLevel="1">
|
||||
<projectFiles>
|
||||
<directory name="."/>
|
||||
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
|
||||
</projectFiles>
|
||||
|
||||
<plugins>
|
||||
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
|
||||
</plugins>
|
||||
</psalm>
|
||||
"""
|
||||
|
||||
Scenario: CacheInterface::get has the same return type as the passed callback
|
||||
Given I have the following code
|
||||
"""
|
||||
<?php
|
||||
|
||||
use Psr\Cache\CacheItemInterface;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
function test(CacheInterface $cache): stdClass
|
||||
{
|
||||
return $cache->get('key', function (CacheItemInterface $item, bool &$save): stdClass {
|
||||
return new stdClass();
|
||||
});
|
||||
}
|
||||
|
||||
"""
|
||||
When I run Psalm
|
||||
Then I see no errors
|
Loading…
Reference in New Issue
Block a user