Open ghostwriter opened 1 month ago
Hi, this feature is internal. We don't use for public yet. How do you use the deprecated interface?
SetListInterface
is implemented on a few SetList ValueObjects, similar to rector
Before deprecation:
After deprecation:
Config:
use Ghostwriter\MockeryRector\MockeryLevelSetList;
use Ghostwriter\MockeryRector\MockerySetList;
use Ghostwriter\MockeryRector\Rule\ExtendMockeryTestCaseRector;
use Ghostwriter\MockeryRector\Rule\HamcrestToPHPUnitRector;
use Ghostwriter\MockeryRector\Rule\PHPUnitToMockeryRector;
use Ghostwriter\MockeryRector\Rule\ProphecyToMockeryRector;
use Ghostwriter\MockeryRector\Rule\ShouldReceiveToAllowsRector;
use Ghostwriter\MockeryRector\Rule\ShouldReceiveToExpectsRector;
use Ghostwriter\MockeryRector\Rule\UseMockeryPHPUnitIntegrationTraitRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
// ExtendMockeryTestCaseRector::class,
// HamcrestToPHPUnitRector::class,
// PHPUnitToMockeryRector::class,
// ProphecyToMockeryRector::class,
// ShouldReceiveToAllowsRector::class,
// ShouldReceiveToExpectsRector::class,
// UseMockeryPHPUnitIntegrationTraitRector::class,
])
->withSets([
// version sets
MockerySetList::MOCKERY_1_6, // v1.6.0
MockerySetList::MOCKERY_2_0, // v2.0.0
// or level sets
MockeryLevelSetList::UP_TO_MOCKERY_1_6, // v0.1.0 - v1.6.0
MockeryLevelSetList::UP_TO_MOCKERY_2_0, // v0.1.0 - v2.0.0
// or migration sets
MockerySetList::PHPUNIT_TO_MOCKERY, // PHPUnit to Mockery
MockerySetList::PROPHECY_TO_MOCKERY, // Prophecy to Mockery
]);
I would like to use the ComposerTriggeredSet
feature.
I would like to see a withSetProviders(string ...$setProviders)
method that accepts FQCN (string) of a class that implements SetProviderInterface
which we can check via is_a($setProvider, SetProviderInterface::class, true)
.
return RectorConfig::configure()
->withSetProviders(
PHPSetProvider::class,
PHPUnitSetProvider::class,
MockerySetProvider::class,
);
class RectorConfigBuilder
{
/**
* @var array<class-string<SetProviderInterface>>
*/
private array $setProviders = [];
/**
* @param class-string<SetProviderInterface> ...$setProviders
*/
public function withSetProviders(string ...$setProviders): self
{
foreach ($setProviders as $setProvider) {
if (! is_a($setProvider, SetProviderInterface::class, true)) {
throw new InvalidConfigurationException(sprintf(
'Set provider "%s" must implement "%s"',
$setProvider,
SetProviderInterface::class
));
}
$this->setProviders[] = $setProvider;
}
return $this;
}
public function __invoke(RectorConfig $rectorConfig): void
{
// @experimental 2024-07
if ($this->setProviders !== []) {
$setProviderCollector = new SetProviderCollector(array_map(
static fn (string $setProvider): SetProviderInterface =>
$rectorConfig->make($setProvider),
$this->setProviders
));
foreach ($setProviderCollector->provideSets() as $set) {
$this->setGroups[] = $set->getGroupName();
}
}
// @experimental 2024-06
if ($this->setGroups !== []) {
$setProviderCollector ??= $rectorConfig->make(SetProviderCollector::class);
$setManager = new SetManager($setProviderCollector);
$this->groupLoadedSets = $setManager->matchBySetGroups($this->setGroups);
}
}
}
Hi,
SetListInterface
was deprecated.Question
Can you please provide documentation or examples on how to register a class that implements the
SetProviderInterface
usingRectorConfigBuilder
orRectorConfig
.It is unclear how to properly implement and register the new interface.
Thank you.