Browse Source

adjust tests to deprecate Plugin:load()

saeid 7 years ago
parent
commit
b78eae9d85

+ 1 - 2
tests/TestCase/Core/AppTest.php

@@ -218,12 +218,11 @@ class AppTest extends TestCase
     public function testPathWithPlugins()
     {
         $basepath = TEST_APP . 'Plugin' . DS;
-        $this->loadPlugins('TestPlugin');
+        $this->loadPlugins(['TestPlugin', 'Company/TestPluginThree']);
 
         $result = App::path('Controller', 'TestPlugin');
         $this->assertPathEquals($basepath . 'TestPlugin' . DS . 'src' . DS . 'Controller' . DS, $result[0]);
 
-        $this->loadPlugins('Company/TestPluginThree');
         $result = App::path('Controller', 'Company/TestPluginThree');
         $expected = $basepath . 'Company' . DS . 'TestPluginThree' . DS . 'src' . DS . 'Controller' . DS;
         $this->assertPathEquals($expected, $result[0]);

+ 120 - 88
tests/TestCase/Core/PluginTest.php

@@ -53,9 +53,11 @@ class PluginTest extends TestCase
      */
     public function testLoad()
     {
-        Plugin::load('TestPlugin');
-        $expected = ['TestPlugin'];
-        $this->assertEquals($expected, Plugin::loaded());
+        $this->deprecated(function () {
+            Plugin::load('TestPlugin');
+            $expected = ['TestPlugin'];
+            $this->assertEquals($expected, Plugin::loaded());
+        });
     }
 
     /**
@@ -65,9 +67,11 @@ class PluginTest extends TestCase
      */
     public function testLoadConcreteClass()
     {
-        Plugin::load('TestPlugin');
-        $instance = Plugin::getCollection()->get('TestPlugin');
-        $this->assertSame(TestPlugin::class, get_class($instance));
+        $this->deprecated(function () {
+            Plugin::load('TestPlugin');
+            $instance = Plugin::getCollection()->get('TestPlugin');
+            $this->assertSame(TestPlugin::class, get_class($instance));
+        });
     }
 
     /**
@@ -77,9 +81,11 @@ class PluginTest extends TestCase
      */
     public function testLoadDynamicClass()
     {
-        Plugin::load('TestPluginTwo');
-        $instance = Plugin::getCollection()->get('TestPluginTwo');
-        $this->assertSame(BasePlugin::class, get_class($instance));
+        $this->deprecated(function () {
+            Plugin::load('TestPluginTwo');
+            $instance = Plugin::getCollection()->get('TestPluginTwo');
+            $this->assertSame(BasePlugin::class, get_class($instance));
+        });
     }
 
     /**
@@ -89,14 +95,14 @@ class PluginTest extends TestCase
      */
     public function testUnload()
     {
-        Plugin::load('TestPlugin');
+        $this->loadPlugins(['TestPlugin' => ['bootstrap' => false, 'routes' => false]]);
         $expected = ['TestPlugin'];
         $this->assertEquals($expected, Plugin::loaded());
 
         Plugin::unload('TestPlugin');
         $this->assertEquals([], Plugin::loaded());
 
-        Plugin::load('TestPlugin');
+        $this->loadPlugins(['TestPlugin' => ['bootstrap' => false, 'routes' => false]]);
         $expected = ['TestPlugin'];
         $this->assertEquals($expected, Plugin::loaded());
 
@@ -111,14 +117,16 @@ class PluginTest extends TestCase
      */
     public function testLoadWithAutoload()
     {
-        $this->assertFalse(class_exists('Company\TestPluginFive\Utility\Hello'));
-        Plugin::load('Company/TestPluginFive', [
-            'autoload' => true,
-        ]);
-        $this->assertTrue(
-            class_exists('Company\TestPluginFive\Utility\Hello'),
-            'Class should be loaded'
-        );
+        $this->deprecated(function () {
+            $this->assertFalse(class_exists('Company\TestPluginFive\Utility\Hello'));
+            Plugin::load('Company/TestPluginFive', [
+                'autoload' => true,
+            ]);
+            $this->assertTrue(
+                class_exists('Company\TestPluginFive\Utility\Hello'),
+                'Class should be loaded'
+            );
+        });
     }
 
     /**
@@ -128,19 +136,21 @@ class PluginTest extends TestCase
      */
     public function testLoadWithAutoloadAndBootstrap()
     {
-        Plugin::load(
-            'Company/TestPluginFive',
-            [
-                'autoload' => true,
-                'bootstrap' => true
-            ]
-        );
-        $this->assertTrue(Configure::read('PluginTest.test_plugin_five.autoload'));
-        $this->assertEquals('loaded plugin five bootstrap', Configure::read('PluginTest.test_plugin_five.bootstrap'));
-        $this->assertTrue(
-            class_exists('Company\TestPluginFive\Utility\Hello'),
-            'Class should be loaded'
-        );
+        $this->deprecated(function () {
+            Plugin::load(
+                'Company/TestPluginFive',
+                [
+                    'autoload' => true,
+                    'bootstrap' => true
+                ]
+            );
+            $this->assertTrue(Configure::read('PluginTest.test_plugin_five.autoload'));
+            $this->assertEquals('loaded plugin five bootstrap', Configure::read('PluginTest.test_plugin_five.bootstrap'));
+            $this->assertTrue(
+                class_exists('Company\TestPluginFive\Utility\Hello'),
+                'Class should be loaded'
+            );
+        });
     }
 
     /**
@@ -150,13 +160,15 @@ class PluginTest extends TestCase
      */
     public function testLoadWithBootstrap()
     {
-        Plugin::load('TestPlugin', ['bootstrap' => true]);
-        $this->assertTrue(Plugin::loaded('TestPlugin'));
-        $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
+        $this->deprecated(function () {
+            Plugin::load('TestPlugin', ['bootstrap' => true]);
+            $this->assertTrue(Plugin::loaded('TestPlugin'));
+            $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
 
-        Plugin::load('Company/TestPluginThree', ['bootstrap' => true]);
-        $this->assertTrue(Plugin::loaded('Company/TestPluginThree'));
-        $this->assertEquals('loaded plugin three bootstrap', Configure::read('PluginTest.test_plugin_three.bootstrap'));
+            Plugin::load('Company/TestPluginThree', ['bootstrap' => true]);
+            $this->assertTrue(Plugin::loaded('Company/TestPluginThree'));
+            $this->assertEquals('loaded plugin three bootstrap', Configure::read('PluginTest.test_plugin_three.bootstrap'));
+        });
     }
 
     /**
@@ -166,12 +178,14 @@ class PluginTest extends TestCase
      */
     public function testLoadWithBootstrapDisableBootstrapHook()
     {
-        Plugin::load('TestPlugin', ['bootstrap' => true]);
-        $this->assertTrue(Plugin::loaded('TestPlugin'));
-        $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
+        $this->deprecated(function () {
+            Plugin::load('TestPlugin', ['bootstrap' => true]);
+            $this->assertTrue(Plugin::loaded('TestPlugin'));
+            $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
 
-        $plugin = Plugin::getCollection()->get('TestPlugin');
-        $this->assertFalse($plugin->isEnabled('bootstrap'), 'Should be disabled as hook has been run.');
+            $plugin = Plugin::getCollection()->get('TestPlugin');
+            $this->assertFalse($plugin->isEnabled('bootstrap'), 'Should be disabled as hook has been run.');
+        });
     }
 
     /**
@@ -199,9 +213,11 @@ class PluginTest extends TestCase
      */
     public function testLoadSingleWithPathConfig()
     {
-        Configure::write('plugins.TestPlugin', APP);
-        Plugin::load('TestPlugin');
-        $this->assertEquals(APP . 'src' . DS, Plugin::classPath('TestPlugin'));
+        $this->deprecated(function () {
+            Configure::write('plugins.TestPlugin', APP);
+            Plugin::load('TestPlugin');
+            $this->assertEquals(APP . 'src' . DS, Plugin::classPath('TestPlugin'));
+        });
     }
 
     /**
@@ -211,9 +227,11 @@ class PluginTest extends TestCase
      */
     public function testLoadMultiple()
     {
-        Plugin::load(['TestPlugin', 'TestPluginTwo']);
-        $expected = ['TestPlugin', 'TestPluginTwo'];
-        $this->assertEquals($expected, Plugin::loaded());
+        $this->deprecated(function () {
+            Plugin::load(['TestPlugin', 'TestPluginTwo']);
+            $expected = ['TestPlugin', 'TestPluginTwo'];
+            $this->assertEquals($expected, Plugin::loaded());
+        });
     }
 
     /**
@@ -223,11 +241,13 @@ class PluginTest extends TestCase
      */
     public function testLoadMultipleWithDefaults()
     {
-        Plugin::load(['TestPlugin', 'TestPluginTwo'], ['bootstrap' => true, 'routes' => false]);
-        $expected = ['TestPlugin', 'TestPluginTwo'];
-        $this->assertEquals($expected, Plugin::loaded());
-        $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
-        $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
+        $this->deprecated(function () {
+            Plugin::load(['TestPlugin', 'TestPluginTwo'], ['bootstrap' => true, 'routes' => false]);
+            $expected = ['TestPlugin', 'TestPluginTwo'];
+            $this->assertEquals($expected, Plugin::loaded());
+            $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
+            $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
+        });
     }
 
     /**
@@ -237,14 +257,16 @@ class PluginTest extends TestCase
      */
     public function testLoadMultipleWithDefaultsAndOverride()
     {
-        Plugin::load(
-            ['TestPlugin', 'TestPluginTwo' => ['routes' => false]],
-            ['bootstrap' => true, 'routes' => true]
-        );
-        $expected = ['TestPlugin', 'TestPluginTwo'];
-        $this->assertEquals($expected, Plugin::loaded());
-        $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
-        $this->assertNull(Configure::read('PluginTest.test_plugin_two.bootstrap'));
+        $this->deprecated(function () {
+            Plugin::load(
+                ['TestPlugin', 'TestPluginTwo' => ['routes' => false]],
+                ['bootstrap' => true, 'routes' => true]
+            );
+            $expected = ['TestPlugin', 'TestPluginTwo'];
+            $this->assertEquals($expected, Plugin::loaded());
+            $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
+            $this->assertNull(Configure::read('PluginTest.test_plugin_two.bootstrap'));
+        });
     }
 
     /**
@@ -272,8 +294,10 @@ class PluginTest extends TestCase
      */
     public function testLoadNotFound()
     {
-        $this->expectException(\Cake\Core\Exception\MissingPluginException::class);
-        Plugin::load('MissingPlugin');
+        $this->deprecated(function () {
+            $this->expectException(\Cake\Core\Exception\MissingPluginException::class);
+            Plugin::load('MissingPlugin');
+        });
     }
 
     /**
@@ -283,7 +307,7 @@ class PluginTest extends TestCase
      */
     public function testPath()
     {
-        Plugin::load(['TestPlugin', 'TestPluginTwo', 'Company/TestPluginThree']);
+        $this->loadPlugins(['TestPlugin', 'TestPluginTwo', 'Company/TestPluginThree']);
         $expected = TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS;
         $this->assertPathEquals(Plugin::path('TestPlugin'), $expected);
 
@@ -312,7 +336,7 @@ class PluginTest extends TestCase
      */
     public function testClassPath()
     {
-        Plugin::load(['TestPlugin', 'TestPluginTwo', 'Company/TestPluginThree']);
+        $this->loadPlugins(['TestPlugin', 'TestPluginTwo', 'Company/TestPluginThree']);
         $expected = TEST_APP . 'Plugin' . DS . 'TestPlugin' . DS . 'src' . DS;
         $this->assertPathEquals(Plugin::classPath('TestPlugin'), $expected);
 
@@ -341,12 +365,14 @@ class PluginTest extends TestCase
      */
     public function testLoadAll()
     {
-        Plugin::loadAll();
-        $expected = [
-            'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
-            'TestPluginFour', 'TestPluginTwo', 'TestTheme'
-        ];
-        $this->assertEquals($expected, Plugin::loaded());
+        $this->deprecated(function () {
+            Plugin::loadAll();
+            $expected = [
+                'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
+                'TestPluginFour', 'TestPluginTwo', 'TestTheme'
+            ];
+            $this->assertEquals($expected, Plugin::loaded());
+        });
     }
 
     /**
@@ -356,9 +382,11 @@ class PluginTest extends TestCase
      */
     public function testLoadAllWithPathConfig()
     {
-        Configure::write('plugins.FakePlugin', APP);
-        Plugin::loadAll();
-        $this->assertContains('FakePlugin', Plugin::loaded());
+        $this->deprecated(function () {
+            Configure::write('plugins.FakePlugin', APP);
+            Plugin::loadAll();
+            $this->assertContains('FakePlugin', Plugin::loaded());
+        });
     }
 
     /**
@@ -368,9 +396,11 @@ class PluginTest extends TestCase
      */
     public function testLoadAllWithPluginAlreadyLoaded()
     {
-        Plugin::load('Company/TestPluginThree', ['bootstrap' => false]);
-        Plugin::loadAll(['bootstrap' => true, 'ignoreMissing' => true]);
-        $this->assertEmpty(Configure::read('PluginTest.test_plugin_three.bootstrap'));
+        $this->deprecated(function () {
+            Plugin::load('Company/TestPluginThree', ['bootstrap' => false]);
+            Plugin::loadAll(['bootstrap' => true, 'ignoreMissing' => true]);
+            $this->assertEmpty(Configure::read('PluginTest.test_plugin_three.bootstrap'));
+        });
     }
 
     /**
@@ -380,16 +410,18 @@ class PluginTest extends TestCase
      */
     public function testLoadAllWithDefaults()
     {
-        $defaults = ['bootstrap' => true, 'ignoreMissing' => true];
-        Plugin::loadAll([$defaults]);
-        $expected = [
-            'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
-            'TestPluginFour', 'TestPluginTwo', 'TestTheme'
-        ];
-        $this->assertEquals($expected, Plugin::loaded());
-        $this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap'));
-        $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
-        $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
+        $this->deprecated(function () {
+            $defaults = ['bootstrap' => true, 'ignoreMissing' => true];
+            Plugin::loadAll([$defaults]);
+            $expected = [
+                'Company', 'ParentPlugin', 'PluginJs', 'TestPlugin',
+                'TestPluginFour', 'TestPluginTwo', 'TestTheme'
+            ];
+            $this->assertEquals($expected, Plugin::loaded());
+            $this->assertEquals('loaded js plugin bootstrap', Configure::read('PluginTest.js_plugin.bootstrap'));
+            $this->assertEquals('loaded plugin bootstrap', Configure::read('PluginTest.test_plugin.bootstrap'));
+            $this->assertEquals('loaded plugin two bootstrap', Configure::read('PluginTest.test_plugin_two.bootstrap'));
+        });
     }
 
     /**

+ 17 - 14
tests/TestCase/Http/BaseApplicationTest.php

@@ -191,19 +191,21 @@ class BaseApplicationTest extends TestCase
      */
     public function testPluginBootstrapInteractWithPluginLoad()
     {
-        Plugin::load('TestPlugin', ['bootstrap' => true]);
-        $app = $this->getMockForAbstractClass(
-            BaseApplication::class,
-            [$this->path]
-        );
-        $this->assertTrue(Configure::check('PluginTest.test_plugin.bootstrap'));
-        Configure::delete('PluginTest.test_plugin.bootstrap');
+        $this->deprecated(function () {
+            Plugin::load('TestPlugin', ['bootstrap' => true]);
+            $app = $this->getMockForAbstractClass(
+                BaseApplication::class,
+                [$this->path]
+            );
+            $this->assertTrue(Configure::check('PluginTest.test_plugin.bootstrap'));
+            Configure::delete('PluginTest.test_plugin.bootstrap');
 
-        $this->assertNull($app->pluginBootstrap());
-        $this->assertFalse(
-            Configure::check('PluginTest.test_plugin.bootstrap'),
-            'Key should not be set, as plugin has already had bootstrap run'
-        );
+            $this->assertNull($app->pluginBootstrap());
+            $this->assertFalse(
+                Configure::check('PluginTest.test_plugin.bootstrap'),
+                'Key should not be set, as plugin has already had bootstrap run'
+            );
+        });
     }
 
     /**
@@ -219,8 +221,9 @@ class BaseApplicationTest extends TestCase
             [$this->path]
         );
         $app->addPlugin('ParentPlugin');
-        $app->pluginBootstrap();
-
+        $this->deprecated(function () use ($app) {
+            $app->pluginBootstrap();
+        });
         $this->assertTrue(
             Configure::check('ParentPlugin.bootstrap'),
             'Plugin bootstrap should be run'

+ 2 - 4
tests/TestCase/ORM/Locator/TableLocatorTest.php

@@ -362,8 +362,7 @@ class TableLocatorTest extends TestCase
      */
     public function testGetMultiplePlugins()
     {
-        $this->loadPlugins('TestPlugin');
-        $this->loadPlugins('TestPluginTwo');
+        $this->loadPlugins(['TestPlugin', 'TestPluginTwo']);
 
         $app = $this->_locator->get('Comments');
         $plugin1 = $this->_locator->get('TestPlugin.Comments');
@@ -577,8 +576,7 @@ class TableLocatorTest extends TestCase
      */
     public function testRemovePlugin()
     {
-        $this->loadPlugins('TestPlugin');
-        $this->loadPlugins('TestPluginTwo');
+        $this->loadPlugins(['TestPlugin', 'TestPluginTwo']);
 
         $app = $this->_locator->get('Comments');
         $this->_locator->get('TestPlugin.Comments');

+ 0 - 2
tests/TestCase/View/HelperTest.php

@@ -122,8 +122,6 @@ class HelperTest extends TestCase
      */
     public function testThatHelperHelpersAreNotAttached()
     {
-        Plugin::loadAll();
-
         $events = $this->getMockBuilder('\Cake\Event\EventManager')->getMock();
         $this->View->setEventManager($events);