Skip to content

Commit d2ada95

Browse files
committed
Update plugin and tests to work correctly with composer v2 plugin api
1 parent 597a3d8 commit d2ada95

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

src/johnpbloch/Composer/WordPressCorePlugin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ public function activate( Composer $composer, IOInterface $io ) {
3838
$composer->getInstallationManager()->addInstaller( $installer );
3939
}
4040

41+
public function deactivate(Composer $composer, IOInterface $io)
42+
{
43+
}
44+
45+
public function uninstall(Composer $composer, IOInterface $io)
46+
{
47+
}
4148
}

tests/phpunit/WordPressCorePluginTest.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,54 @@
2424
use Composer\Composer;
2525
use Composer\Config;
2626
use Composer\Installer\InstallationManager;
27+
use Composer\IO\IOInterface;
2728
use Composer\IO\NullIO;
29+
use Composer\Plugin\PluginInterface;
30+
use Composer\Test\Mock\HttpDownloaderMock;
31+
use Composer\Util\HttpDownloader;
32+
use Composer\Util\Loop;
2833
use johnpbloch\Composer\WordPressCorePlugin;
2934
use PHPUnit\Framework\TestCase;
3035

3136
class WordPressCorePluginTest extends TestCase {
3237

3338
public function testActivate() {
34-
$composer = new Composer();
35-
$installationManager = new InstallationManager();
39+
$composer = new Composer();
40+
$composer->setConfig( new Config() );
41+
$nullIO = new NullIO();
42+
$installationManager = $this->getInstallationManager( $composer, $nullIO );
3643
$composer->setInstallationManager( $installationManager );
3744
$composer->setConfig( new Config() );
3845

3946
$plugin = new WordPressCorePlugin();
40-
$plugin->activate( $composer, new NullIO() );
47+
$plugin->activate( $composer, $nullIO );
4148

4249
$installer = $installationManager->getInstaller( 'wordpress-core' );
4350

4451
$this->assertInstanceOf( '\johnpbloch\Composer\WordPressCoreInstaller', $installer );
4552
}
4653

54+
/**
55+
* @param Composer $composer
56+
* @param IOInterface $io
57+
*
58+
* @return InstallationManager
59+
*/
60+
private function getInstallationManager( $composer, $io ) {
61+
$installationManager = null;
62+
switch ( explode( '.', PluginInterface::PLUGIN_API_VERSION )[0] ) {
63+
case '1':
64+
$installationManager = new InstallationManager();
65+
break;
66+
case '2':
67+
default:
68+
$http = new HttpDownloader( $io, $composer->getConfig() );
69+
$loop = new Loop( $http );
70+
$installationManager = new InstallationManager( $loop, $io );
71+
break;
72+
}
73+
74+
return $installationManager;
75+
}
76+
4777
}

0 commit comments

Comments
 (0)