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

Add database ready check before calling $controller->doInit() #9301

Open
timkung opened this issue Oct 22, 2019 · 1 comment
Open

Add database ready check before calling $controller->doInit() #9301

timkung opened this issue Oct 22, 2019 · 1 comment

Comments

@timkung
Copy link
Contributor

timkung commented Oct 22, 2019

Affected Version

SS4.x

Description

In SapphireTest::start() there is a call to $controller->doInit();, however this causes issues if there are any DB calls in a custom init() method or if using the onBeforeInit hook as the DB is not ready at the point this is called.

Steps to Reproduce

Create a unit test for a class that is using the onBeforeInit hook and make a DB call in that method, e.g.

<?php

class TestMe extends DataExtension
{
    public function onBeforeInit()
    {
        // this will cause the unit test to fail as DB is not setup yet
        $pages = Page::get();
    }
}
@mlewis-everley
Copy link

This can happen outside of testing as well, for example I added some code to Controller::onBeforeInit() that gets from values from SiteConfig and it causes a Table not found error when the site first builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants