Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CacheInterface.stubphp from symfony contracts #74

Merged
merged 1 commit into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions src/Stubs/common/CacheInterface.stubphp
Original file line number Diff line number Diff line change
@@ -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 changes: 37 additions & 0 deletions tests/acceptance/acceptance/CacheInterface.feature
Original file line number Diff line number Diff line change
@@ -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