-
Notifications
You must be signed in to change notification settings - Fork 0
Activate "required plugins" before the tested plugin #10
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b8ac185
Return the output of WP-CLI
meszarosrob c2d967f
Add task to activate dependencies of tested plugins
meszarosrob 070eb35
Add tests for activating dependencies of tested plugins
meszarosrob 34de4a9
Make things slighly more readable
meszarosrob b15aceb
Handle some weirded defintions
meszarosrob 6c6789a
Make tests slightly more managable
meszarosrob 63debc9
Fix phpstan
meszarosrob a4449eb
Drop seemingly unneeded filter empty callback
meszarosrob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,52 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Syde\WpPhpUnitIntegration\Task; | ||
|
|
||
| use Syde\WpPhpUnitIntegration\Path\LocalDependencyPath; | ||
| use Syde\WpPhpUnitIntegration\WpCli; | ||
| use Symfony\Component\Filesystem\Path; | ||
|
|
||
| readonly class ActivateTestedPluginDependencies implements Task | ||
| { | ||
| public function __construct( | ||
| private LocalDependencyPath $packageRootPath, | ||
| private WpCli $wpCli, | ||
| ) { | ||
| } | ||
|
|
||
| public function execute(): void | ||
| { | ||
| $testedPluginName = Path::getFilenameWithoutExtension($this->packageRootPath->path()); | ||
|
|
||
| foreach ($this->requiredPlugins($testedPluginName) as $requiredPlugin) { | ||
| $this->wpCli->run(['plugin', 'activate', $requiredPlugin]); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @return string[] | ||
| */ | ||
| private function requiredPlugins(string $pluginName): array | ||
| { | ||
| $requiredPluginsField = json_decode( | ||
| $this->wpCli->run([ | ||
| 'plugin', | ||
| 'get', | ||
| $pluginName, | ||
| '--field=requires_plugins', | ||
| '--format=json', | ||
| ]), | ||
| flags: JSON_THROW_ON_ERROR, | ||
| ); | ||
|
|
||
| if (!is_string($requiredPluginsField) || $requiredPluginsField === '') { | ||
| return []; | ||
| } | ||
|
|
||
| return array_filter( | ||
| array_map('trim', explode(',', $requiredPluginsField)), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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
138 changes: 138 additions & 0 deletions
138
tests/phpunit/Functional/Task/ActivateTestedPluginDependenciesTest.php
This file contains hidden or 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,138 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Syde\WpPhpUnitIntegration\Tests\Functional\Task; | ||
|
|
||
| use PHPUnit\Framework\Attributes\DataProvider; | ||
| use Syde\WpPhpUnitIntegration\Task\ActivateTestedPluginDependencies; | ||
| use Syde\WpPhpUnitIntegration\Tests\FunctionalTestCase; | ||
| use Syde\WpPhpUnitIntegration\WpCli; | ||
|
|
||
| final class ActivateTestedPluginDependenciesTest extends FunctionalTestCase | ||
| { | ||
| public function testPluginActivateNotCalledWhenNoRequiredPlugins(): void | ||
| { | ||
| $this->filesystem->mkdir($this->workspace . '/acme'); | ||
|
|
||
| $wpCli = $this->createMock(WpCli::class); | ||
| $wpCli | ||
| ->expects($this->once()) | ||
| ->method('run') | ||
| ->with( | ||
| [ | ||
| 'plugin', | ||
| 'get', | ||
| 'acme', | ||
| '--field=requires_plugins', | ||
| '--format=json', | ||
| ], | ||
| ) | ||
| ->willReturn('""'); | ||
|
|
||
| (new ActivateTestedPluginDependencies( | ||
| $this->localDependencyPath($this->workspace . '/acme'), | ||
| $wpCli, | ||
| ))->execute(); | ||
| } | ||
|
|
||
| /** | ||
| * @param list<array{0: list<string>, 1: string}> $wpCliArgsReturnMap | ||
| */ | ||
| #[DataProvider('wpCliArgsReturnMapProvider')] | ||
| public function testRequiredPluginsAreActivated(array $wpCliArgsReturnMap): void | ||
| { | ||
| $this->filesystem->mkdir($this->workspace . '/acme'); | ||
|
|
||
| $wpCli = $this->createMock(WpCli::class); | ||
| $wpCli | ||
| ->expects($this->exactly(count($wpCliArgsReturnMap))) | ||
| ->method('run') | ||
| ->willReturnMap($wpCliArgsReturnMap); | ||
|
|
||
| (new ActivateTestedPluginDependencies( | ||
| $this->localDependencyPath($this->workspace . '/acme'), | ||
| $wpCli, | ||
| ))->execute(); | ||
| } | ||
|
|
||
| public static function wpCliArgsReturnMapProvider(): \Generator | ||
| { | ||
| yield [ | ||
| [ | ||
| [ | ||
| [ | ||
| 'plugin', | ||
| 'get', | ||
| 'acme', | ||
| '--field=requires_plugins', | ||
| '--format=json', | ||
| ], | ||
| '"woocommerce"', | ||
| ], | ||
| [ | ||
| [ | ||
| 'plugin', | ||
| 'activate', | ||
| 'woocommerce', | ||
| ], | ||
| '', | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| yield [ | ||
| [ | ||
| [ | ||
| [ | ||
| 'plugin', | ||
| 'get', | ||
| 'acme', | ||
| '--field=requires_plugins', | ||
| '--format=json', | ||
| ], | ||
| '"woocommerce,, ,"', | ||
| ], | ||
| [ | ||
| [ | ||
| 'plugin', | ||
| 'activate', | ||
| 'woocommerce', | ||
| ], | ||
| '', | ||
| ], | ||
| ], | ||
| ]; | ||
|
|
||
| yield [ | ||
| [ | ||
| [ | ||
| [ | ||
| 'plugin', | ||
| 'get', | ||
| 'acme', | ||
| '--field=requires_plugins', | ||
| '--format=json', | ||
| ], | ||
| '"woocommerce, woocommerce-subscriptions"', | ||
| ], | ||
| [ | ||
| [ | ||
| 'plugin', | ||
| 'activate', | ||
| 'woocommerce', | ||
| ], | ||
| '', | ||
| ], | ||
| [ | ||
| [ | ||
| 'plugin', | ||
| 'activate', | ||
| 'woocommerce-subscriptions', | ||
| ], | ||
| '', | ||
| ], | ||
| ], | ||
| ]; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note:
This is now done in multiple files https://github.com/search?q=repo%3Ainpsyde%2Fwp-phpunit-integration%20getFilenameWithoutExtension&type=code.
In a future PR, I would like to move this "filename without extension" functionality to some central place, perhaps a service class, rather than doing it in the tasks themselves.