1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-04 02:27:59 +01:00
psalm/tests/Config/PluginListTest.php
Bruce Weirdan 1cf5153700
Test parallelization (#4045)
* Run tests in random order

Being able to run tests in any order is a pre-requisite for being able
to run them in parallel.

* Reset type coverage between tests, fix affected tests

* Reset parser and lexer between test runs and on php version change

Previously lexer was reset, but parser kept the reference to the old
one, and reference to the parser was kept by StatementsProvider. This
resulted in order-dependent tests - if the parser was first initialized
with phpVersion set to 7.4 then arrow functions worked fine, but were
failing when the parser was initially constructed with settings for 7.3

This can be demonstrated on current master by upgrading to
nikic/php-parser:4.9 and running:

```
vendor/bin/phpunit --no-coverage --filter="inferredArgArrowFunction" tests/ClosureTest.php
```

Now all tests using PHP 7.4 features must set the PHP version
accordingly.

* Marked more tests using 7.4 syntax

* Reset newline-between-annotation flag between tests

* Resolve real paths before passing them to checkPaths

When checkPaths is called from psalm.php the paths are resolved, so we
just mimicking SUT behaviour here.

* Restore newline-between-annotations in DocCommentTest

* Tweak Appveyor caches

* Tweak TravisCI caches

* Tweak CircleCI caches

* Run tests in parallel

Use `vendor/bin/paratest` instead of `vendor/bin/phpunit`

* Use default paratest runner on Windows

WrapperRunner is not supported on Windows.

* TRAVIS_TAG could be empty

* Restore appveyor conditional caching
2020-08-23 10:32:07 -04:00

176 lines
4.8 KiB
PHP

<?php
namespace Psalm\Tests\Config;
use Prophecy\Prophecy\ObjectProphecy;
use Psalm\Config;
use Psalm\Internal\PluginManager\ComposerLock;
use Psalm\Internal\PluginManager\ConfigFile;
use Psalm\Internal\PluginManager\PluginList;
use Psalm\Internal\RuntimeCaches;
/** @group PluginManager */
class PluginListTest extends \Psalm\Tests\TestCase
{
/** @var ObjectProphecy<ConfigFile> */
private $config_file;
/** @var ObjectProphecy<Config> */
private $config;
/** @var ObjectProphecy<ComposerLock> */
private $composer_lock;
public function setUp() : void
{
RuntimeCaches::clearAll();
$this->config = $this->prophesize(Config::class);
$this->config->getPluginClasses()->willReturn([]);
$this->config_file = $this->prophesize(ConfigFile::class);
$this->config_file->getConfig()->willReturn($this->config->reveal());
$this->composer_lock = $this->prophesize(ComposerLock::class);
$this->composer_lock->getPlugins()->willReturn([]);
}
/**
* @return void
* @test
*/
public function pluginsPresentInConfigAreEnabled()
{
$this->config->getPluginClasses()->willReturn([
['class' => 'a\b\c', 'config' => null],
['class' => 'c\d\e', 'config' => null],
]);
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->assertSame([
'a\b\c' => null,
'c\d\e' => null,
], $plugin_list->getEnabled());
}
/**
* @return void
* @test
*/
public function pluginsPresentInPackageLockOnlyAreAvailable()
{
$this->config->getPluginClasses()->willReturn([
['class' => 'a\b\c', 'config' => null],
]);
$this->composer_lock->getPlugins()->willReturn([
'vendor/package' => 'a\b\c',
'another-vendor/another-package' => 'c\d\e',
]);
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->assertSame([
'c\d\e' => 'another-vendor/another-package',
], $plugin_list->getAvailable());
}
/**
* @return void
* @test
*/
public function pluginsPresentInPackageLockAndConfigHavePluginPackageName()
{
$this->config->getPluginClasses()->willReturn([
['class' => 'a\b\c', 'config' => null],
]);
$this->composer_lock->getPlugins()->willReturn([
'vendor/package' => 'a\b\c',
]);
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->assertSame([
'a\b\c' => 'vendor/package',
], $plugin_list->getEnabled());
}
/**
* @return void
* @test
*/
public function canFindPluginClassByClassName()
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->assertSame('a\b\c', $plugin_list->resolvePluginClass('a\b\c'));
}
/**
* @return void
* @test
*/
public function canFindPluginClassByPackageName()
{
$this->composer_lock->getPlugins()->willReturn([
'vendor/package' => 'a\b\c',
]);
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->assertSame('a\b\c', $plugin_list->resolvePluginClass('vendor/package'));
}
/**
* @return void
* @test
*/
public function enabledPackageIsEnabled()
{
$this->config->getPluginClasses()->willReturn([
['class' => 'a\b\c', 'config' => null],
]);
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->assertTrue($plugin_list->isEnabled('a\b\c'));
}
/**
* @return void
* @test
*/
public function errorsOutWhenTryingToResolveUnknownPlugin()
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp('/unknown plugin/i');
$plugin_list->resolvePluginClass('vendor/package');
}
/**
* @return void
* @test
*/
public function pluginsAreEnabledInConfigFile()
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->config_file->addPlugin('a\b\c')->shouldBeCalled();
$plugin_list->enable('a\b\c');
}
/**
* @return void
* @test
*/
public function pluginsAreDisabledInConfigFile()
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$this->config_file->removePlugin('a\b\c')->shouldBeCalled();
$plugin_list->disable('a\b\c');
}
}