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

Switch from phpspec/prophecy to mockery/mockery #8755

Merged
merged 4 commits into from Nov 25, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions composer.json
Expand Up @@ -30,9 +30,11 @@
"dnoegel/php-xdg-base-dir": "^0.1.1",
"felixfbecker/advanced-json-rpc": "^3.1",
"felixfbecker/language-server-protocol": "^1.5",
"mockery/mockery": "^1.5",
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0",
"nikic/php-parser": "^4.13",
"openlss/lib-array2xml": "^1.0",
"psalm/plugin-mockery": "^1.1",
"sebastian/diff": "^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0 || ^6.0",
"symfony/filesystem": "^5.4 || ^6.0",
Expand All @@ -47,15 +49,12 @@
"brianium/paratest": "^4.0||^6.0",
"nunomaduro/mock-final-classes": "^1.1",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpspec/prophecy": "^1.15",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"psalm/plugin-phpunit": "^0.18",
"slevomat/coding-standard": "^7.0",
"phpstan/phpdoc-parser": "1.6.4",
"squizlabs/php_codesniffer": "^3.6",
"symfony/process": "^4.3 || ^5.0 || ^6.0",
"weirdan/prophecy-shim": "^1.0 || ^2.0"
"symfony/process": "^4.3 || ^5.0 || ^6.0"
},
"suggest": {
"ext-igbinary": "^2.0.5 is required, used to serialize caching data",
Expand Down
2 changes: 2 additions & 0 deletions psalm.xml.dist
Expand Up @@ -38,6 +38,7 @@
<file name="vendor/felixfbecker/advanced-json-rpc/lib/Dispatcher.php" />
<directory name="vendor/netresearch/jsonmapper" />
<directory name="vendor/phpunit" />
<directory name="vendor/mockery/mockery"/>
<file name="vendor/nikic/php-parser/lib/PhpParser/Node/UnionType.php" />
</ignoreFiles>
</projectFiles>
Expand All @@ -52,6 +53,7 @@
<plugin filename="examples/plugins/FunctionCasingChecker.php"/>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
<plugin filename="examples/plugins/InternalChecker.php"/>
<pluginClass class="Psalm\MockeryPlugin\Plugin"/>
</plugins>

<issueHandlers>
Expand Down
3 changes: 2 additions & 1 deletion src/Psalm/Config.php
Expand Up @@ -2176,7 +2176,8 @@ public function visitStubFiles(Codebase $codebase, ?Progress $progress = null):
}

if (extension_loaded('random')) {
$ext_random_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR . 'ext-random.phpstub';
$ext_random_path = $dir_lvl_2 . DIRECTORY_SEPARATOR . 'stubs' . DIRECTORY_SEPARATOR
. 'extensions' . DIRECTORY_SEPARATOR . 'ext-random.phpstub';
$this->internal_stubs[] = $ext_random_path;
}

Expand Down
3 changes: 3 additions & 0 deletions src/Psalm/Type/MutableUnion.php
Expand Up @@ -212,6 +212,9 @@ final class MutableUnion implements TypeNode, Stringable
*/
public $different = false;

/** @psalm-suppress PossiblyUnusedProperty */
public bool $propagate_parent_nodes = false;

/**
* @psalm-external-mutation-free
* @param non-empty-array<Atomic> $types
Expand Down
65 changes: 33 additions & 32 deletions tests/Config/PluginListTest.php
Expand Up @@ -3,8 +3,9 @@
namespace Psalm\Tests\Config;

use InvalidArgumentException;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;
use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Mockery\MockInterface;
use Psalm\Config;
use Psalm\Internal\PluginManager\ComposerLock;
use Psalm\Internal\PluginManager\ConfigFile;
Expand All @@ -15,42 +16,42 @@
/** @group PluginManager */
class PluginListTest extends TestCase
{
use ProphecyTrait;
use MockeryPHPUnitIntegration;

/** @var ObjectProphecy<ConfigFile> */
/** @var ConfigFile&MockInterface */
private $config_file;

/** @var ObjectProphecy<Config> */
/** @var Config&MockInterface */
private $config;

/** @var ObjectProphecy<ComposerLock> */
/** @var ComposerLock&MockInterface */
private $composer_lock;

public function setUp(): void
{
RuntimeCaches::clearAll();

$this->config = $this->prophesize(Config::class);
$this->config->getPluginClasses()->willReturn([]);
$this->config = Mockery::mock(Config::class);
$this->config->allows()->getPluginClasses()->andReturns([])->byDefault();

$this->config_file = $this->prophesize(ConfigFile::class);
$this->config_file->getConfig()->willReturn($this->config->reveal());
$this->config_file = Mockery::mock(ConfigFile::class);
$this->config_file->allows()->getConfig()->andReturns($this->config)->byDefault();

$this->composer_lock = $this->prophesize(ComposerLock::class);
$this->composer_lock->getPlugins()->willReturn([]);
$this->composer_lock = Mockery::mock(ComposerLock::class);
$this->composer_lock->allows()->getPlugins()->andReturns([])->byDefault();
}

/**
* @test
*/
public function pluginsPresentInConfigAreEnabled(): void
{
$this->config->getPluginClasses()->willReturn([
$this->config->expects()->getPluginClasses()->andReturns([
['class' => 'a\b\c', 'config' => null],
['class' => 'c\d\e', 'config' => null],
]);

$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);

$this->assertSame([
'a\b\c' => null,
Expand All @@ -63,16 +64,16 @@ public function pluginsPresentInConfigAreEnabled(): void
*/
public function pluginsPresentInPackageLockOnlyAreAvailable(): void
{
$this->config->getPluginClasses()->willReturn([
$this->config->expects()->getPluginClasses()->andReturns([
['class' => 'a\b\c', 'config' => null],
]);

$this->composer_lock->getPlugins()->willReturn([
$this->composer_lock->expects()->getPlugins()->andReturns([
'vendor/package' => 'a\b\c',
'another-vendor/another-package' => 'c\d\e',
]);

$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);

$this->assertSame([
'c\d\e' => 'another-vendor/another-package',
Expand All @@ -84,15 +85,15 @@ public function pluginsPresentInPackageLockOnlyAreAvailable(): void
*/
public function pluginsPresentInPackageLockAndConfigHavePluginPackageName(): void
{
$this->config->getPluginClasses()->willReturn([
$this->config->expects()->getPluginClasses()->andReturns([
['class' => 'a\b\c', 'config' => null],
]);

$this->composer_lock->getPlugins()->willReturn([
$this->composer_lock->expects()->getPlugins()->andReturns([
'vendor/package' => 'a\b\c',
]);

$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);

$this->assertSame([
'a\b\c' => 'vendor/package',
Expand All @@ -104,7 +105,7 @@ public function pluginsPresentInPackageLockAndConfigHavePluginPackageName(): voi
*/
public function canFindPluginClassByClassName(): void
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);
$this->assertSame('a\b\c', $plugin_list->resolvePluginClass('a\b\c'));
}

Expand All @@ -113,11 +114,11 @@ public function canFindPluginClassByClassName(): void
*/
public function canFindPluginClassByPackageName(): void
{
$this->composer_lock->getPlugins()->willReturn([
$this->composer_lock->expects()->getPlugins()->andReturns([
'vendor/package' => 'a\b\c',
]);

$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);
$this->assertSame('a\b\c', $plugin_list->resolvePluginClass('vendor/package'));
}

Expand All @@ -126,11 +127,11 @@ public function canFindPluginClassByPackageName(): void
*/
public function canShowAvailablePluginsWithoutAConfigFile(): void
{
$this->composer_lock->getPlugins()->willReturn([
$this->composer_lock->expects()->getPlugins()->andReturns([
'vendor/package' => 'a\b\c',
'another-vendor/another-package' => 'c\d\e',
]);
$plugin_list = new PluginList(null, $this->composer_lock->reveal());
$plugin_list = new PluginList(null, $this->composer_lock);

$this->assertSame([
'a\b\c' => 'vendor/package',
Expand All @@ -143,11 +144,11 @@ public function canShowAvailablePluginsWithoutAConfigFile(): void
*/
public function enabledPackageIsEnabled(): void
{
$this->config->getPluginClasses()->willReturn([
$this->config->expects()->getPluginClasses()->andReturns([
['class' => 'a\b\c', 'config' => null],
]);

$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);

$this->assertTrue($plugin_list->isEnabled('a\b\c'));
}
Expand All @@ -157,7 +158,7 @@ public function enabledPackageIsEnabled(): void
*/
public function errorsOutWhenTryingToResolveUnknownPlugin(): void
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessageMatches('/unknown plugin/i');
$plugin_list->resolvePluginClass('vendor/package');
Expand All @@ -168,9 +169,9 @@ public function errorsOutWhenTryingToResolveUnknownPlugin(): void
*/
public function pluginsAreEnabledInConfigFile(): void
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);

$this->config_file->addPlugin('a\b\c')->shouldBeCalled();
$this->config_file->expects()->addPlugin('a\b\c');

$plugin_list->enable('a\b\c');
}
Expand All @@ -180,9 +181,9 @@ public function pluginsAreEnabledInConfigFile(): void
*/
public function pluginsAreDisabledInConfigFile(): void
{
$plugin_list = new PluginList($this->config_file->reveal(), $this->composer_lock->reveal());
$plugin_list = new PluginList($this->config_file, $this->composer_lock);

$this->config_file->removePlugin('a\b\c')->shouldBeCalled();
$this->config_file->expects()->removePlugin('a\b\c');

$plugin_list->disable('a\b\c');
}
Expand Down