Skip to content

Commit

Permalink
Deprecate Plugin::unload()
Browse files Browse the repository at this point in the history
I missed this earlier when working on new Plugins. This method should go
away along with `Plugin::load()`.

Refs #12682
  • Loading branch information
markstory committed Oct 29, 2018
1 parent 3f46964 commit 835a255
Show file tree
Hide file tree
Showing 59 changed files with 104 additions and 89 deletions.
4 changes: 3 additions & 1 deletion src/Core/Plugin.php
Expand Up @@ -381,12 +381,14 @@ public static function loaded($plugin = null)
* Forgets a loaded plugin or all of them if first parameter is null
*
* @param string|null $plugin name of the plugin to forget
* @deprecated 3.7 This method will be removed in 4.0.0. Use PluginCollection::remove() or clear() instead.
* @return void
*/
public static function unload($plugin = null)
{
deprecationWarning('Plugin::unload() will be removed in 4.0. Use PluginCollection::remove() or clear()');
if ($plugin === null) {
static::$plugins = null;
static::getCollection()->clear();
} else {
static::getCollection()->remove($plugin);
}
Expand Down
12 changes: 12 additions & 0 deletions src/Core/PluginCollection.php
Expand Up @@ -158,6 +158,18 @@ public function remove($name)
return $this;
}

/**
* Remove all plugins from the collection
*
* @return $this
*/
public function clear()
{
$this->plugins = [];

return $this;
}

/**
* Check whether the named plugin exists in the collection.
*
Expand Down
1 change: 0 additions & 1 deletion tests/TestCase/Auth/FormAuthenticateTest.php
Expand Up @@ -298,7 +298,6 @@ public function testPluginModel()
'updated' => new Time('2007-03-17 01:18:31')
];
$this->assertEquals($expected, $result);
Plugin::unload();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Auth/PasswordHasherFactoryTest.php
Expand Up @@ -44,7 +44,7 @@ public function testBuild()
$this->loadPlugins(['TestPlugin']);
$hasher = PasswordHasherFactory::build('TestPlugin.Legacy');
$this->assertInstanceof('TestPlugin\Auth\LegacyPasswordHasher', $hasher);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Cache/CacheTest.php
Expand Up @@ -315,7 +315,7 @@ public function testConfigWithLibAndPluginEngines()
Cache::drop('libEngine');
Cache::drop('pluginLibEngine');

Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Command/HelpCommandTest.php
Expand Up @@ -34,7 +34,7 @@ public function setUp()
parent::setUp();
$this->setAppNamespace();
$this->useCommandRunner(true);
Plugin::unload();
Plugin::getCollection()->clear();
$app = $this->getMockForAbstractClass(
BaseApplication::class,
['']
Expand All @@ -50,7 +50,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand All @@ -63,7 +63,7 @@ public function testMainNoCommandsFallback()
$this->exec('help');
$this->assertExitCode(Shell::CODE_SUCCESS);
$this->assertCommandList();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Console/CommandCollectionTest.php
Expand Up @@ -296,6 +296,6 @@ public function testDiscoverPlugin()
'Long names are stored as well'
);
$this->assertSame($result['company'], $result['company/test_plugin_three.company']);
Plugin::unload();
Plugin::getCollection()->clear();
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Console/HelperRegistryTest.php
Expand Up @@ -127,6 +127,6 @@ public function testLoadWithAlias()

$result = $this->helpers->loaded();
$this->assertEquals(['SimpleAliased', 'SomeHelper'], $result, 'loaded() results are wrong.');
Plugin::unload();
Plugin::getCollection()->clear();
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Console/ShellDispatcherTest.php
Expand Up @@ -49,7 +49,7 @@ public function tearDown()
{
parent::tearDown();
ShellDispatcher::resetAliases();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -141,7 +141,7 @@ public function testInitialize()
'TestPlugin\Model\Table\TestPluginCommentsTable',
$this->Shell->TestPluginComments
);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down Expand Up @@ -170,7 +170,7 @@ public function testLoadModel()
'TestPlugin\Model\Table\TestPluginCommentsTable',
$this->Shell->TestPluginComments
);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Console/TaskRegistryTest.php
Expand Up @@ -94,7 +94,7 @@ public function testLoadPluginTask()
$result = $this->Tasks->load('TestPlugin.OtherTask');
$this->assertInstanceOf('TestPlugin\Shell\Task\OtherTaskTask', $result, 'Task class is wrong.');
$this->assertInstanceOf('TestPlugin\Shell\Task\OtherTaskTask', $this->Tasks->OtherTask, 'Class is wrong');
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand All @@ -119,6 +119,6 @@ public function testLoadWithAlias()

$result = $this->Tasks->loaded();
$this->assertEquals(['CommandAliased', 'SomeTask'], $result, 'loaded() results are wrong.');
Plugin::unload();
Plugin::getCollection()->clear();
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/ComponentRegistryTest.php
Expand Up @@ -54,7 +54,7 @@ public function tearDown()
{
parent::tearDown();
unset($this->Components);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Controller/ControllerTest.php
Expand Up @@ -257,7 +257,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Core/AppTest.php
Expand Up @@ -32,7 +32,7 @@ class AppTest extends TestCase
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Core/BasePluginTest.php
Expand Up @@ -39,7 +39,7 @@ class BasePluginTest extends TestCase
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Core/Configure/Engine/IniConfigTest.php
Expand Up @@ -221,7 +221,7 @@ public function testReadPluginValue()

$result = $engine->read('TestPlugin.nested');
$this->assertEquals('foo', $result['database']['db']['password']);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Core/Configure/Engine/JsonConfigTest.php
Expand Up @@ -142,7 +142,7 @@ public function testReadPluginValue()
$result = $engine->read('TestPlugin.load');
$this->assertArrayHasKey('plugin_load', $result);

Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Core/Configure/Engine/PhpConfigTest.php
Expand Up @@ -128,7 +128,7 @@ public function testReadPluginValue()
$result = $engine->read('TestPlugin.load');
$this->assertArrayHasKey('plugin_load', $result);

Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Core/ConfigureTest.php
Expand Up @@ -406,7 +406,7 @@ public function testLoadPlugin()
$expected = '/test_app/Plugin/TestPlugin/Config/more.load.php';
$config = Configure::read('plugin_more_load');
$this->assertEquals($expected, $config);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
39 changes: 21 additions & 18 deletions tests/TestCase/Core/PluginTest.php
Expand Up @@ -32,7 +32,7 @@ class PluginTest extends TestCase
public function setUp()
{
parent::setUp();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand All @@ -43,7 +43,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down Expand Up @@ -91,26 +91,29 @@ public function testLoadDynamicClass()
/**
* Tests unloading plugins
*
* @deprecated
* @return void
*/
public function testUnload()
{
$this->loadPlugins(['TestPlugin' => ['bootstrap' => false, 'routes' => false]]);
$expected = ['TestPlugin'];
$this->assertEquals($expected, Plugin::loaded());
$this->assertTrue(Plugin::isLoaded('TestPlugin'));

Plugin::unload('TestPlugin');
$this->assertEquals([], Plugin::loaded());
$this->assertFalse(Plugin::isLoaded('TestPlugin'));

$this->loadPlugins(['TestPlugin' => ['bootstrap' => false, 'routes' => false]]);
$expected = ['TestPlugin'];
$this->assertEquals($expected, Plugin::loaded());

Plugin::unload('TestFakePlugin');
$this->assertEquals($expected, Plugin::loaded());
$this->assertFalse(Plugin::isLoaded('TestFakePlugin'));
$this->deprecated(function () {
$this->loadPlugins(['TestPlugin' => ['bootstrap' => false, 'routes' => false]]);
$expected = ['TestPlugin'];
$this->assertEquals($expected, Plugin::loaded());
$this->assertTrue(Plugin::isLoaded('TestPlugin'));

Plugin::unload('TestPlugin');
$this->assertEquals([], Plugin::loaded());
$this->assertFalse(Plugin::isLoaded('TestPlugin'));

$this->loadPlugins(['TestPlugin' => ['bootstrap' => false, 'routes' => false]]);
$expected = ['TestPlugin'];
$this->assertEquals($expected, Plugin::loaded());

Plugin::unload('TestFakePlugin');
$this->assertEquals($expected, Plugin::loaded());
$this->assertFalse(Plugin::isLoaded('TestFakePlugin'));
});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Datasource/ConnectionManagerTest.php
Expand Up @@ -68,7 +68,7 @@ class ConnectionManagerTest extends TestCase
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
ConnectionManager::drop('test_variant');
ConnectionManager::dropAlias('other_name');
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Error/ErrorHandlerTest.php
Expand Up @@ -112,7 +112,7 @@ public function tearDown()
{
parent::tearDown();
Log::reset();
Plugin::unload();
Plugin::getCollection()->clear();
if ($this->_restoreError) {
restore_error_handler();
restore_exception_handler();
Expand Down
3 changes: 1 addition & 2 deletions tests/TestCase/Error/ExceptionRendererTest.php
Expand Up @@ -183,7 +183,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
if ($this->_restoreError) {
restore_error_handler();
}
Expand Down Expand Up @@ -884,7 +884,6 @@ public function testMissingPluginRenderSafeWithPlugin()
$body = (string)$response->getBody();
$this->assertContains('test plugin error500', $body);
$this->assertContains('Not Found', $body);
Plugin::unload();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/BaseApplicationTest.php
Expand Up @@ -49,7 +49,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Http/SessionTest.php
Expand Up @@ -88,7 +88,7 @@ public function tearDown()
{
unset($_SESSION);
parent::tearDown();
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/I18n/I18nTest.php
Expand Up @@ -56,7 +56,7 @@ public function tearDown()
I18n::clear();
I18n::setDefaultFormatter('default');
I18n::setLocale($this->locale);
Plugin::unload();
Plugin::getCollection()->clear();
Cache::clear(false, '_cake_core_');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Log/LogTest.php
Expand Up @@ -64,7 +64,7 @@ public function testImportingLoggers()

Log::write(LOG_INFO, 'TestPluginLog is not a BaseLog descendant');

Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestCase/Mailer/EmailTest.php
Expand Up @@ -1792,7 +1792,7 @@ public function testSendRenderThemed()
$this->assertContains('Message-ID: ', $result['headers']);
$this->assertContains('To: ', $result['headers']);
$this->assertContains('/test_theme/img/test.jpg', $result['message']);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down Expand Up @@ -1975,7 +1975,7 @@ public function testSendRenderPlugin()
$result = $this->Email->send();
$this->assertContains('Here is your value: 12345', $result['message']);
$this->assertContains('This email was sent using the TestPlugin.', $result['message']);
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/AssociationTest.php
Expand Up @@ -540,7 +540,7 @@ public function testTargetPlugin()
$this->assertSame('TestPlugin.ThisAssociationName', $table->getRegistryAlias());
$this->assertSame('comments', $table->getTable());
$this->assertSame('ThisAssociationName', $table->getAlias());
Plugin::unload();
Plugin::getCollection()->clear();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/BehaviorRegistryTest.php
Expand Up @@ -46,7 +46,7 @@ public function setUp()
*/
public function tearDown()
{
Plugin::unload();
Plugin::getCollection()->clear();
unset($this->Table, $this->EventManager, $this->Behaviors);
parent::tearDown();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/ORM/Locator/TableLocatorTest.php
Expand Up @@ -68,7 +68,7 @@ public function setUp()
*/
public function tearDown()
{
Plugin::unload();
Plugin::getCollection()->clear();
parent::tearDown();
}

Expand Down

0 comments on commit 835a255

Please sign in to comment.