-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check also for Node\Scalar\Encapsed (#592)
Co-authored-by: Matt Glaman <nmd.matt@gmail.com>
- Loading branch information
1 parent
0b93022
commit a40fb53
Showing
3 changed files
with
190 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace mglaman\PHPStanDrupal\Tests\Rules; | ||
|
||
use mglaman\PHPStanDrupal\Rules\Drupal\PluginManager\PluginManagerSetsCacheBackendRule; | ||
use mglaman\PHPStanDrupal\Tests\DrupalRuleTestCase; | ||
use PHPStan\Rules\Rule; | ||
|
||
final class PluginManagerSetsCacheBackendRuleTest extends DrupalRuleTestCase | ||
{ | ||
|
||
protected function getRule(): Rule | ||
{ | ||
return new PluginManagerSetsCacheBackendRule(); | ||
} | ||
|
||
/** | ||
* @dataProvider ruleData | ||
*/ | ||
public function testRule(string $path, array $errorMessages): void | ||
{ | ||
$this->analyse([$path], $errorMessages); | ||
} | ||
|
||
public static function ruleData(): \Generator | ||
{ | ||
yield [ | ||
__DIR__ . '/data/plugin-manager-cache-backend.php', | ||
[ | ||
[ | ||
'Missing cache backend declaration for performance.', | ||
12 | ||
], | ||
[ | ||
'plugins cache tag might be unclear and does not contain the cache key in it.', | ||
112, | ||
] | ||
] | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
<?php | ||
|
||
namespace PluginManagerCacheBackend; | ||
|
||
use Drupal\Core\Cache\CacheBackendInterface; | ||
use Drupal\Core\Extension\ModuleHandlerInterface; | ||
use Drupal\Core\Plugin\DefaultPluginManager; | ||
|
||
class Foo extends DefaultPluginManager | ||
{ | ||
|
||
public function __construct( | ||
\Traversable $namespaces, | ||
ModuleHandlerInterface $module_handler, | ||
) { | ||
parent::__construct( | ||
'Plugin/Foo', | ||
$namespaces, | ||
$module_handler, | ||
'FooInterface', | ||
'FooAnnotation', | ||
); | ||
} | ||
|
||
} | ||
|
||
class Bar extends DefaultPluginManager | ||
{ | ||
|
||
public function __construct( | ||
\Traversable $namespaces, | ||
ModuleHandlerInterface $module_handler, | ||
CacheBackendInterface $cache_backend | ||
) { | ||
parent::__construct( | ||
'Plugin/Bar', | ||
$namespaces, | ||
$module_handler, | ||
'BarInterface', | ||
'BarAnnotation', | ||
); | ||
$this->setCacheBackend($cache_backend, 'bar_plugins'); | ||
} | ||
|
||
} | ||
|
||
class Baz extends DefaultPluginManager | ||
{ | ||
|
||
public function __construct( | ||
\Traversable $namespaces, | ||
ModuleHandlerInterface $module_handler, | ||
CacheBackendInterface $cache_backend, | ||
string $type, | ||
) { | ||
parent::__construct( | ||
'Plugin/Bar', | ||
$namespaces, | ||
$module_handler, | ||
'BarInterface', | ||
'BarAnnotation', | ||
); | ||
$this->setCacheBackend($cache_backend, 'bar_' . $type . '_plugins'); | ||
} | ||
|
||
} | ||
|
||
class Qux extends DefaultPluginManager | ||
{ | ||
|
||
public function __construct( | ||
\Traversable $namespaces, | ||
ModuleHandlerInterface $module_handler, | ||
CacheBackendInterface $cache_backend, | ||
string $type, | ||
) { | ||
parent::__construct( | ||
'Plugin/Bar', | ||
$namespaces, | ||
$module_handler, | ||
'BarInterface', | ||
'BarAnnotation', | ||
); | ||
$this->setCacheBackend($cache_backend, "bar_{$type}_plugins"); | ||
} | ||
|
||
} | ||
|
||
class BarTags extends DefaultPluginManager | ||
{ | ||
|
||
public function __construct( | ||
\Traversable $namespaces, | ||
ModuleHandlerInterface $module_handler, | ||
CacheBackendInterface $cache_backend | ||
) { | ||
parent::__construct( | ||
'Plugin/Bar', | ||
$namespaces, | ||
$module_handler, | ||
'BarInterface', | ||
'BarAnnotation', | ||
); | ||
$this->setCacheBackend($cache_backend, 'bar_plugins', ['bar_plugins']); | ||
} | ||
|
||
} | ||
|
||
class BarTagsNotClear extends DefaultPluginManager | ||
{ | ||
|
||
public function __construct( | ||
\Traversable $namespaces, | ||
ModuleHandlerInterface $module_handler, | ||
CacheBackendInterface $cache_backend | ||
) { | ||
parent::__construct( | ||
'Plugin/Bar', | ||
$namespaces, | ||
$module_handler, | ||
'BarInterface', | ||
'BarAnnotation', | ||
); | ||
$this->setCacheBackend($cache_backend, 'bar_plugins', ['plugins']); | ||
} | ||
|
||
} |