Running Codeception for all tests the Craft Edition defaults to Solo before overriding project configuration
jamiesykescreode opened this issue · comments
Description
When running codeception run
for my plugin I encounter an issue when running tests.
In ApplicationTrait.php line 490:
Craft Pro is required for this
I traced the stack back through to the following event and the issue during the saveUserGroup
function. Which I would expect if the Edition of Craft is set to Solo.
In my project configuration I have set the version to Pro but these settings don't seem to persist at this point. The full event I am trying to run is attached below:
Event::on(
Plugins::class,
Plugins::EVENT_AFTER_INSTALL_PLUGIN,
function (PluginEvent $event) {
if ($event->plugin === $this) {
// We were just installed
$magicLoginUserGroup = new UserGroup();
$magicLoginUserGroup->name = 'Magic Login';
$magicLoginUserGroup->handle = 'magicLoginHandle';
$magicLoginUserGroup->description = Craft::t('magic-login', 'Users within this group were registered with magic login capabilities.');
$groupSaved = Craft::$app
->getUserGroups()
->saveGroup($magicLoginUserGroup);
if (!$groupSaved) {
Craft::error(Craft::t('magic-login', 'Could not create Magic Login User group.'), __METHOD__);
}
Craft::info(Craft::t('magic-login', 'Created Magic Login User Group.'), __METHOD__);
}
}
);
Steps to reproduce
- Pull the code from the plugin here: https://github.com/creode/magic-login/tree/feature/40-user_groups_broken
- Composer install to install dependencies.
Run vendor/bin/codecept run
to run the test suite. An error about the Craft Version should appear even though the project config sets the version to be Pro.
Additional info
- Craft version: 3.6.11
- PHP version: 7.3.27
- Database driver & version: mysql (MariaDB 10.5.9)
- Plugins & versions: Magic Login (attached above) - 1.0.0
Looking further into this issue it seems that a plugin is installed in the craft\test\Craft
class lifecycle, before the project configuration directory is created.
This effectively means for me that I cannot run tests on events surrounding plugin installation which require Pro functionality (in this instance create a new user group) due to the Edition being hardcoded at startup.
I'm happy to accept that what I am doing is non standard (being pretty new to Craft) and if there is a workaround to this, I'll take it 😄 .