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.
This commit is contained in:
Samuel Georges 2017-04-05 08:23:39 +10:00
parent 68f515ba0e
commit 08e7fa4296

View File

@ -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;
}
}
}