From 08e7fa42966bb7c4ca460ffd81fa930b7333d007 Mon Sep 17 00:00:00 2001 From: Samuel Georges Date: Wed, 5 Apr 2017 08:23:39 +1000 Subject: [PATCH] Adds a helper for fetching the plugin object This is useful when you need to "boot" or "register" certain areas of the plugin itself, eg: $plugin = $this->getPluginObject(); $plugin->registerSubscriptionEvents(); Calling boot() or register() may work too but not always, sometimes there can be things you don't want registered. Hence why it doesn't occur automatically. --- tests/PluginTestCase.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tests/PluginTestCase.php b/tests/PluginTestCase.php index 581780869..0a25dd2ec 100644 --- a/tests/PluginTestCase.php +++ b/tests/PluginTestCase.php @@ -151,6 +151,21 @@ abstract class PluginTestCase extends Illuminate\Foundation\Testing\TestCase Artisan::call('plugin:refresh', ['name' => $code]); } + /** + * Returns a plugin object from its code, useful for registering events, etc. + * @return PluginBase + */ + protected function getPluginObject($code = null) + { + if ($code === null) { + $code = $this->guessPluginCodeFromTest(); + } + + if (isset($this->pluginTestCaseLoadedPlugins[$code])) { + return $this->pluginTestCaseLoadedPlugins[$code]; + } + } + /** * The models in October use a static property to store their events, these * will need to be targeted and reset ready for a new test cycle. @@ -198,4 +213,4 @@ abstract class PluginTestCase extends Illuminate\Foundation\Testing\TestCase return $result; } -} \ No newline at end of file +}