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

Feature Request: Add withSetProviders method for Registering SetProviderInterface #8720

Open
ghostwriter opened this issue Jul 5, 2024 · 4 comments · May be fixed by rectorphp/rector-src#6515

Comments

@ghostwriter
Copy link

Hi,

SetListInterface was deprecated.

/**
 * @deprecated This interface needs a reflection to load and uses constant links. 
 * Now we changed to services provider architecture that can be used and registerd easily. 
 * Use @see SetProviderInterface instead
 */
interface SetListInterface
{
}
// src/Set/Contract/SetListInterface.php
interface SetProviderInterface
{
    /**
     * @return SetInterface[]
     */
    public function provide(): array;
}
// src/Set/Contract/SetProviderInterface.php

Question

Can you please provide documentation or examples on how to register a class that implements the SetProviderInterface using RectorConfigBuilder or RectorConfig.

It is unclear how to properly implement and register the new interface.

Thank you.

@TomasVotruba
Copy link
Member

Hi, this feature is internal. We don't use for public yet.
How do you use the deprecated interface?

@ghostwriter
Copy link
Author

ghostwriter commented Jul 6, 2024

SetListInterface is implemented on a few SetList ValueObjects, similar to rector

Before deprecation:

After deprecation:

https://github.com/ghostwriter/mockery-rector/blob/28d60268ff72943df51c561f556d6eb5c412bcfc/src/MockerySetProvider.php

https://github.com/ghostwriter/mockery-rector/blob/28d60268ff72943df51c561f556d6eb5c412bcfc/src/MockerySetList.php

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
    ]);

@ghostwriter
Copy link
Author

ghostwriter commented Jul 6, 2024

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,
    );

@ghostwriter
Copy link
Author

Hi @TomasVotruba,

With the introduction of Composer-Based Sets and Custom Set Providers, Currently, requiring a PR for every custom SetProvider developers create feels like an unnecessary hurdle.

If your parameter is missing, send us a PR to enable it.

It would be great to simplify this step for broader usability with the requested method (or a similar one).

@ghostwriter ghostwriter linked a pull request Nov 27, 2024 that will close this issue
@ghostwriter ghostwriter changed the title Missing Documentation for Registering SetProviderInterface Feature Request: Add withSetProviders method for Registering SetProviderInterface Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants