Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant GRAV_USER_INSTANCE already defined #2620

Closed
Regaez opened this issue Aug 13, 2019 · 0 comments · Fixed by #2621
Closed

Constant GRAV_USER_INSTANCE already defined #2620

Regaez opened this issue Aug 13, 2019 · 0 comments · Fixed by #2621

Comments

@Regaez
Copy link
Contributor

Regaez commented Aug 13, 2019

When trying to write Unit Tests for my plugin, following the Codeception/_bootstrap.php approach like is done in the Grav repo, if I try and get a user before every test:

protected function _before()
{
    $grav = Fixtures::get('grav');
    $this->grav = $grav();
    $this->user = $this->grav['accounts']->load('testuser');
}

Then it throws an error:

Constant GRAV_USER_INSTANCE already defined

I did a little digging, and it seems that the AccountsServiceProvider.php is blindly defining a constant and not checking if it first exists.

This is fine when your PHP process instantiates Grav once, but when trying to write unit tests and reinstantiating Grav multiple times, it means only the first test will pass and all the rest will throw an error due to $this->grav['accounts']->load in the _before() function trying to redefine a constant.

I believe a simple fix would be wrapping them in a check within AccountsServiceProvider.php like so:

if (!defined('GRAV_USER_INSTANCE')) {
    define('GRAV_USER_INSTANCE', 'DATA');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants